Reputation: 2145
I'm trying to use WinSock.h header file, but I get either one of the errors below: in VS2010 (C++):
Unresolved External Symbol to [the function included in winsock.g, e.g socket()]
in gcc command line (C):
Undefined Reference to [the function included in winsock.g, e.g socket()]
code is simple: Just including the Winsock.h header file and then
SOCKET s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
I get an error on socket()
& closesocket()
functions...!
I searched in Stackoverflow and found several topics over this, but they all suggested a change in the header file. I can't change WinSock.h here, so I need a solution in the actual code that uses the header file. Any ideas?
Upvotes: 0
Views: 1574
Reputation: 20654
According to the documentation, you need ws2_32.lib
.
Go to Project->Properties->Linker->Additional dependencies and add ws2_32.lib
.
EDIT:
That should be Project->Properties->Linker->Input->Additional Dependencies
Upvotes: 5
Reputation: 224924
Those are linker errors, not compiler errors. You need to link the WinSock library. For gcc, that means adding the library to your link command line:
gcc -Lpath/to/winsock/library -o myApplication myObject.o wsock32.lib
I don't know anything about Visual Studio, I'm afraid, but this link might help.
Upvotes: 0