how to link winsock.lib?

2019-01-09 14:32发布

问题:

in a my c++ class I would use the socket.

I have some errors when linking because, seocndo me, the library missing winsock.lib

I include these:

#ifdef WIN32
  #include <winsock.h>         
  typedef int socklen_t;
  typedef char raw_type;       
#endif

How can i link the library winsock.lib? I use Windows xp and visual studio 2005.

回答1:

The lib file of winsock is "ws_32.lib" (or "ws2_32.lib"), please make sure you've added it.



回答2:

I am unable to find direct link shows what lib to use, but if you study this, you will find out, that windows sockets 1.1 is supported through WSOCK32.DLL, that mean, possible, that you want WSock32.Lib, instead of Ws2_32.lib for windows socket version 2.

WSock32.Lib is a part of Windows SDK (I have v6.0A, v7.0A installed, both has this library)