C++ 如何链接 winsock.lib?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9249886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 12:32:45  来源:igfitidea点击:

How to link winsock.lib?

c++socketsvisual-studio-2005windows-xpwinsock

提问by Safari

In my C++ class, I use sockets.

在我的 C++ 类中,我使用套接字。

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

链接时我有一些错误,因为在我看来,缺少库 winsock.lib。

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.

如何链接库winsock.lib?我使用 Windows XP 和 Visual Studio 2005。

回答by ciphor

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

winsock 的 lib 文件是“ws_32.lib”(或“ws2_32.lib”),请确保你已经添加了它。

回答by Lol4t0

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.1is supported through WSOCK32.DLL, that mean, possible, that you want WSock32.Lib, instead of Ws2_32.libfor windows socket version 2.

我无法找到直接的联系说明了什么lib中使用,但如果你研究这个,你会发现,那Windows套接字1.1支持通过WSOCK32.DLL影响,这就意味着,可能的话,你想WSock32.Lib,而不是Ws2_32.libWindows套接字第2版

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

WSock32.LibWindows SDK(我安装了 v6.0A、v7.0A,都有这个库)