Safari
Safari

Reputation: 11935

How to link winsock.lib?

In my C++ class, I use sockets.

I have some errors when linking because, in my opinion, the library winsock.lib is missing.

I included 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.

Upvotes: 27

Views: 67649

Answers (3)

xakepp35
xakepp35

Reputation: 3222

One way is you may add a pragma directive to cpp file:

#pragma comment(lib, "ws2_32.lib")

Another way is that you may to provide it to project settings, using project that builds your binary (dont do it from library project, if you have many under your solution)

Third variant is to provide it as a command line flags if you invoke linker from command line

Upvotes: 1

ciphor
ciphor

Reputation: 8288

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

Upvotes: 33

Lol4t0
Lol4t0

Reputation: 12547

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)

Upvotes: 11

Related Questions