WSAStartup link error

a 夏天 提交于 2019-12-02 06:32:40

问题


I am using EVC++ and I want to compile the program which uses the sockets. I've included

#include <winsock2.h>

And I have included in project properties a path to Ws2.lib But still get the error at link step:

error LNK2019: unresolved external symbol WSAStartup referenced in function ...

How to resolve this problem?


回答1:


#pragma comment(lib,"WS2_32") after all #include's




回答2:


You haven't linked your program with the winsock library. The Winsock 2 library is called ws2_32.lib (static) or ws2_32.dll (dynamic). It should already be on your system; you just need to tell your compiler/linker to link your program against it. The method of doing this varies by compiler, and unfortunately I'm not familiar with EVC++.




回答3:


Have seen this error in codeblock IDE using MinGW. Tried many ways but finally found this solution.

Add(your the path for MinGW installed in your system) C:\Program Files (x86)\CodeBlocks\MinGW\lib\libws2_32 C:\Program Files (x86)\CodeBlocks\MinGW\lib\libwsock32 in codeblock IDE.

How to add: Go to project. build options. Linker setting. click add of link library.

And its done.



来源:https://stackoverflow.com/questions/3359283/wsastartup-link-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!