问题
I installed eclipse, cdt and mingw on my windows XP machine. added C:\MinGW\bin
to my PATH.
Created a new c++ project, with one file in it, test.c. the code in it:
int main(){
int i=1;
}
Trying to build, I get the error:
/mingw/lib/libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to 'WinMain@16'
Notice it's not complaining about test.c
but rather about some main.c
in one of mingw's libs.
What am I doing wrong?
回答1:
You need to save the .c
file first.
回答2:
well, the solution was really weird, but I guess it would make sense to someone more proficient with CDT than me - My main() was inside a .c file. When I changed the suffix to be .cpp, it worked like a charm.
回答3:
main.o from libmingw32.a should not be searched by the linker because the undefined symbol _main from crt2.o is (should be) satisfied by the "int main()" which you wrote.
Please copy & paste the gcc command lines that cdt is executing.
来源:https://stackoverflow.com/questions/3269112/eclipse-cdt-mingw-windows-error-undefined-reference-to-winmain16-on-b