以下是来自http://curl.haxx.se/libcurl/c/sendrecv.html的示例代码的一部分:
static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
{
struct timeval tv;
fd_set infd, outfd, errfd;
int res;
tv.tv_sec = timeout_ms / 1000;
tv.tv_usec= (timeout_ms % 1000) * 1000;
FD_ZERO(&infd);
FD_ZERO(&outfd);
FD_ZERO(&errfd);
FD_SET(sockfd, &errfd); /* always check for error */
if(for_recv)
{
FD_SET(sockfd, &infd);
}
else
{
FD_SET(sockfd, &outfd);
}
///* select() returns the number of signalled sockets or -1 */
res = select(sockfd + 1, &infd, &outfd, &errfd, &tv);
return res;
}
它在 Linux 上运行良好,但是当我将它带到 Visual Studio 2010 时,它抱怨 select() 函数。我正确编译并链接了所有 cURL 库/dll,我什至下载了一些东西作为 http 请求。
但是当我尝试使用套接字 select() 函数时,它会抱怨以下错误:
error LNK2028: unresolved token (0A00034C) "extern "C" int __stdcall select(int,struct fd_set *,struct fd_set *,struct fd_set *,struct timeval const *)" (?select@@$$J220YGHHPAUfd_set@@00PBUtimeval@@@Z) referenced in function "int __cdecl `anonymous namespace'::wait_on_socket(unsigned int,int,long)" (?wait_on_socket@?A0x7d9db21b@@$$FYAHIHJ@Z)
error LNK2019: unresolved external symbol "extern "C" int __stdcall select(int,struct fd_set *,struct fd_set *,struct fd_set *,struct timeval const *)" (?select@@$$J220YGHHPAUfd_set@@00PBUtimeval@@@Z) referenced in function "int __cdecl `anonymous namespace'::wait_on_socket(unsigned int,int,long)" (?wait_on_socket@?A0x7d9db21b@@$$FYAHIHJ@Z)
此外,select() 函数似乎与 Windows 兼容:http: //msdn.microsoft.com/en-us/library/ms740141 (VS.85).aspx
我错过了什么吗?有人可以告诉我如何解决这个问题吗?
谢谢,--鲁迪