I have a project that perfectly compiles in VS and from command line. However, in Eclipse (C++) I get the following error:

C:\Users\Lukas\AppData\Local\Temp\ccHNeQ9u.o: In function `main':
C:\Users\Lukas\eclipse-ws\TCPClient\Debug/../src/TCPClient.cpp:36: undefined reference to `WSAStartup@8'
C:\Users\Lukas\eclipse-ws\TCPClient\Debug/../src/TCPClient.cpp:44: undefined reference to `socket@12'
C:\Users\Lukas\eclipse-ws\TCPClient\Debug/../src/TCPClient.cpp:47: undefined reference to `WSAGetLastError@0'
C:\Users\Lukas\eclipse-ws\TCPClient\Debug/../src/TCPClient.cpp:48: undefined reference to `WSACleanup@0'

g++ "-IC:\\MinGW\\include\\" -Iws2_32 -O0 -g3 -Wall -o "src\\TCPClient.o" "..\\src\\TCPClient.cpp" 
..\src\TCPClient.cpp:24:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(lib, "ws2_32.lib")

I already found this solution (C - Undefined Reference to WSAStartup@8') , which basically says:

Build your project/cpp-file from command line using this syntax: gcc prog.c -o prog -lws2_32 (such that winsock library (-lws2_32) is added at the end of the compiling call)

As already mentioned before: This compiles fine in command line, the generated application works as expected ! I also got it running in VS.

However, not in the eclipse world where I need it. I added "ws2_32" in Properties --> C/C++ Build/Settings already to MinGW C++ Linker --> Libraries and GCC C++ Compiler --> libraries but if I understand the "g++" call there's no adding of "-lws2_32" in Eclipse at the end but directly after "g++". I don't know whether this is relevant. But I know the code does not compile in eclipse.

I also added C:\MinGW\bin and ..\include to the Eclipse-Includes folder of my project.

Does anyone have an idea how to solve this within eclipse?

EDIT: Also tried this, but does not change my error messages:

Menu - Project - Properties - c/c++Build - Settings: Register "Tool Settings" - MinGW C++ Linker - Miscellaneous: Lower Part "other objects"

Add: libwsock32.a from bin folder of MinGW.

(Source: MinGW linker error: winsock)

Best regards, Lukas

0

There are 0 answers