我是VC ++的新手,想知道如何在VC ++中链接“wsock32.lib”。我正在尝试编写一个简单的c ++服务器应用程序,这些是我得到的错误消息。那么我该如何在VC ++中链接一些内容呢? wsock32也是我需要的正确的库吗?
1>------ Build started: Project: bla, Configuration: Debug Win32 ------
1>bla.obj : error LNK2019: unresolved external symbol _closesocket@4 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _send@16 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _recv@16 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _accept@12 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _listen@8 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _bind@12 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _socket@12 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _htons@4 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _main
1>C:\Users\-r.s-\Desktop\bla\Debug\bla.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
答案 0 :(得分:16)
您应该与“ws2_32.lib”库链接。通过pragma指令在项目设置或源代码中指定它:
#pragma comment(lib, "ws2_32.lib")
添加:AFAIK Visual C ++ Express不包含Platform SDK,因此如果您在计算机上找不到库,则应下载并安装Platform SDK并在Visual Studio "VC++ Directories" property page中添加必要的文件夹。