使用 libcurl 在windows平台遇到的问题
1. 遇到如下问题
1>libcurl.lib(easy.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAStartup
1>libcurl.lib(telnet.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAStartup
1>libcurl.lib(easy.obj) : error LNK2001: 无法解析的外部符号 __imp_WSACleanup
1>libcurl.lib(telnet.obj) : error LNK2001: 无法解析的外部符号 __imp_WSACleanup
1>libcurl.lib(ftp.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAGetLastError
1>libcurl.lib(telnet.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAGetLastError
1>libcurl.lib(tftp.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAGetLastError
1>libcurl.lib(asyn-thread.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAGetLastError
1>libcurl.lib(select.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAGetLastError
1>libcurl.lib(sendf.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAGetLastError
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAGetLastError
1>libcurl.lib(select.obj) : error LNK2001: 无法解析的外部符号 __WSAFDIsSet
1>libcurl.lib(select.obj) : error LNK2001: 无法解析的外部符号 __imp_select
1>libcurl.lib(select.obj) : error LNK2001: 无法解析的外部符号 __imp_WSASetLastError
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_WSASetLastError
1>libcurl.lib(curl_addrinfo.obj) : error LNK2001: 无法解析的外部符号 __imp_WSASetLastError
1>libcurl.lib(sendf.obj) : error LNK2001: 无法解析的外部符号 __imp_recv
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_recv
1>libcurl.lib(sendf.obj) : error LNK2001: 无法解析的外部符号 __imp_send
1>libcurl.lib(telnet.obj) : error LNK2001: 无法解析的外部符号 __imp_send
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_bind
1>libcurl.lib(ftp.obj) : error LNK2001: 无法解析的外部符号 __imp_bind
1>libcurl.lib(tftp.obj) : error LNK2001: 无法解析的外部符号 __imp_bind
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_closesocket
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_connect
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_getpeername
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_getsockname
1>libcurl.lib(ftp.obj) : error LNK2001: 无法解析的外部符号 __imp_getsockname
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_getsockopt
1>libcurl.lib(smb.obj) : error LNK2001: 无法解析的外部符号 __imp_htons
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_htons
1>libcurl.lib(curl_addrinfo.obj) : error LNK2001: 无法解析的外部符号 __imp_htons
1>libcurl.lib(ftp.obj) : error LNK2001: 无法解析的外部符号 __imp_htons
1>libcurl.lib(telnet.obj) : error LNK2001: 无法解析的外部符号 __imp_htons
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_ntohs
1>libcurl.lib(ftp.obj) : error LNK2001: 无法解析的外部符号 __imp_ntohs
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_setsockopt
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_socket
1>libcurl.lib(connect.obj) : error LNK2001: 无法解析的外部符号 __imp_WSAIoctl
1>libcurl.lib(curl_addrinfo.obj) : error LNK2001: 无法解析的外部符号 __imp_getaddrinfo
1>libcurl.lib(curl_addrinfo.obj) : error LNK2001: 无法解析的外部符号 __imp_freeaddrinfo
1>libcurl.lib(ftp.obj) : error LNK2001: 无法解析的外部符号 __imp_accept
1>libcurl.lib(ftp.obj) : error LNK2001: 无法解析的外部符号 __imp_listen
1>libcurl.lib(tftp.obj) : error LNK2001: 无法解析的外部符号 __imp_recvfrom
1>libcurl.lib(tftp.obj) : error LNK2001: 无法解析的外部符号 __imp_sendto
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_init
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_unbind_s
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_set_option
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_simple_bind_s
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_search_s
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_msgfree
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_err2string
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_first_entry
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_next_entry
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_first_attribute
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_next_attribute
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_get_values_len
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_value_free_len
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_get_dn
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_memfree
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ber_free
1>libcurl.lib(nonblock.obj) : error LNK2001: 无法解析的外部符号 __imp_ioctlsocket
具体步骤就是:
给工程添加依赖的库:项目->属性->链接器->输入->附加依赖项,把 ws2_32.lib、 winmm.lib、 wldap32.lib添加进去
注意,debug配置用libcurld.lib
2.如出现
error LNK2001: 无法解析的外部符号 __imp_curl_easy_perform
error LNK2001: 无法解析的外部符号 __imp_curl_easy_init
error LNK2001: 无法解析的外部符号 __imp_curl_slist_append
error LNK2001: 无法解析的外部符号 __imp_curl_slist_free_all
error LNK2001: 无法解析的外部符号 __imp_curl_easy_cleanup
error LNK2001: 无法解析的外部符号 __imp_curl_easy_setopt
加入预编译选项:项目->属性->c/c++ ->预处理器->预处理器,把 BUILDING_LIBCURL;HTTP_ONLY复制进去(注意不要丢了";")
3.如出现
1>libcurl.lib(cookie.obj) : error LNK2001: 无法解析的外部符号 __imp_fgets
1>libcurl.lib(netrc.obj) : error LNK2001: 无法解析的外部符号 __imp_fgets
1>libcurl.lib(mime.obj) : error LNK2001: 无法解析的外部符号 __imp_access
1>OLDNAMES.lib(access.obi) : error LNK2001: 无法解析的外部符号 __imp_access
1>libcurl.lib(tftp.obj) : error LNK2001: 无法解析的外部符号 __imp_strstr
1>libcurl.lib(digest.obj) : error LNK2001: 无法解析的外部符号 __imp_strstr
1>libcurl.lib(ftplistparser.obj) : error LNK2001: 无法解析的外部符号 __imp_strstr
1>libcurl.lib(url.obj) : error LNK2001: 无法解析的外部符号 __imp_strstr
1>libcurl.lib(http.obj) : error LNK2001: 无法解析的外部符号 __imp_strstr
1>libcurl.lib(transfer.obj) : error LNK2001: 无法解析的外部符号 __imp_strstr
1>libcurl.lib(ftp.obj) : error LNK2001: 无法解析的外部符号 __imp_strstr
1>libcurl.lib(warnless.obj) : error LNK2001: 无法解析的外部符号 __imp_read
1>OLDNAMES.lib(read.obi) : error LNK2001: 无法解析的外部符号 __imp_read
1>libcurl.lib(warnless.obj) : error LNK2001: 无法解析的外部符号 __imp_write
1>OLDNAMES.lib(write.obi) : error LNK2001: 无法解析的外部符号 __imp_write
1>libcurl.lib(parsedate.obj) : error LNK2001: 无法解析的外部符号 __imp__gmtime64
1>libcurl.lib(file.obj) : error LNK2001: 无法解析的外部符号 __imp_open
1>OLDNAMES.lib(open.obi) : error LNK2001: 无法解析的外部符号 __imp_open
1>libcurl.lib(smb.obj) : error LNK2001: 无法解析的外部符号 __imp__getpid
1>libcurl.lib(system_win32.obj) : error LNK2001: 无法解析的外部符号 __imp__mbspbrk
这个问题 :要 统一代码生成方式,如果是 Debug 就是多线程调试 /MTd,如果是 Release 就是多线程 /MT
C/C++ -> 代码生成 -> 运行库
curl 工程默认是MD ,改成MT就可以了。
4.libcurl出现CURLcode 23 CURLE_WRITE_ERROR错误
百度了下是 write_func 回调函数有问题 ,
因为我编译的是全平台的,windows、linux 系统接口是不同的,回调函数需要定义成不现的函数
#if defined(WIN32) || defined(_WIN32) || defined(WINDOWS)
size_t write_func(char *ptr, size_t size, size_t nmemb, void *userdata) //回调函数
{
std::string &buffer = *(std::string *) userdata;
size_t len = size * nmemb;
for (size_t i = 0; i < len; ++i) {
buffer += *ptr;
++ptr;
}
// LOGE(buffer.c_str());
return len;
}
#else
void write_func(char *ptr, size_t size, size_t nmemb, void *userdata) //回调函数
{
std::string &buffer = *(std::string *) userdata;
size_t len = size * nmemb;
for (size_t i = 0; i < len; ++i) {
buffer += *ptr;
++ptr;
}
// LOGE(buffer.c_str());
}
#endif