Eclipse C++, Compiling via cmd works, compilling in eclipse does not

339 Views Asked by At

I have a TCP Client program (TCPClient.cpp) using winsock library. An *.exe is generated successfully if I use command line with the following call:

g++ TCPClient.cpp -o TCPClient.exe -lws2_32

When I try to compile and link the same script within Eclipse/C++ using MinGW I seem to get the *.o file generated but I get an error when generating the *.exe. Thus, the error is generated if Ecplise/C++ does the following (linker call):

g++ -o TCPClient.exe TCPClient.o -lws2_32 

I get multiple errors:

enter C:\MinGW\bin\ld.exe: Dwarf Error: Could not find abbrev number 84.
./src/TCPClient.o:cygming-crtbegin.c:(.text+0x2a0): multiple definition of
_mingw32_init_mainargs
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../crt2.o:(.text+0x2a0): first defined here C:\MinGW\bin\ld.exe: Dwarf Error: Could not find abbrev number 84. ./src/TCPClient.o:cygming-crtbegin.c:(.text+0x2e0): multiple definition of
mainCRTStartup' c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../crt2.o:(.text+0x2e0): first defined here C:\MinGW\bin\ld.exe: Dwarf Error: Could not find abbrev number 84. ./src/TCPClient.o:cygming-crtbegin.c:(.text+0x300): multiple definition of WinMainCRTStartup' c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../crt2.o:(.text+0x300): first defined here C:\MinGW\bin\ld.exe: Dwarf Error: Could not find abbrev number 84. ./src/TCPClient.o:cygming-crtbegin.c:(.text+0x320): multiple definition of atexit' c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../crt2.o:(.text+0x320): first defined here C:\MinGW\bin\ld.exe: Dwarf Error: Could not find abbrev number 84. ./src/TCPClient.o:cygming-crtbegin.c:(.text+0x330): multiple definition of _onexit' c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../crt2.o:(.text+0x330): first defined here C:\MinGW\bin\ld.exe: Dwarf Error: Could not find abbrev number 84. ./src/TCPClient.o:cygming-crtbegin.c:(.text+0x340): multiple definition of
`__gcc_register_frame' c:/mingw/bin/../lib/gcc/mingw32/6.3.0/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here C:\MinGW\bin\ld.exe: Dwarf Error: Could not find abbrev number 84.here

The following is interesting: I get the same errors if I use the cmd-line and first generate a .o file and then try to generate a *.exe. Both of the following calls in cmd-line result in the error from above:

g++ TCPClient.o -o TCPClient.exe -lws2_32

g++ TCPClient.o -o TCPClient.exe 

This means: If in cmd-line I only specify that I want to generate (a *.exe from my *.cpp) everything works fine. But - as a user - doing those two steps separately does not work.

Cmd-Line g++ call seems to "know" what to do here. As a user I never see the *.o file when directly generating a *.exe. But I think it must be generated anyway? Am I wrong? Why does cmd-line without further specification know how to deal with the .o file? ... Is it possible to find out from any source what a call to "g++" does when called via command line? Of course I want the same settings integrated in eclipse/c++.

1

There are 1 best solutions below

0
On

g++ TCPClient.cpp -o TCPClient.exe -lws2_32

You can get that error if you do -O (capital letter, not zero) instead of -o for the exe file.