VS2017使用libcurl,链接错误

当使用libcurl库出现链接错误,如下

1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_global_init
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_global_cleanup
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_easy_strerror
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_easy_init
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_easy_setopt
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_easy_perform
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_easy_cleanup
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_easy_getinfo
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_easy_recv
1>WebSocketMsg.obj : error LNK2001: unresolved external symbol __imp__curl_easy_send

因已经配置了使用libcurl.lib静态库的属性,如下:

  1. 添加包含目录:project–>Properties–>VC++ Directories–>Include Directories–>添加包含libcurl中头文件curl.h的include目录;

  2. 添加库目录:project–>Properties–>VC++ Directories–>Library Directories–>添加相应的libcurl中的lib文件存放目录;(区分vs的版本)

  3. 添加引用的lib文件名:project–>Properties–>Linker–>Input–>Additional Dependencies–>输入lib文件名libcurl.lib;(区分Debug和Release版本)

  4. 并已经程序中添加了附加依赖库

    #pragma comment(lib, “ws2_32.lib”)
    #pragma comment(lib, “wldap32.lib”)
    #pragma comment(lib, “crypt32.lib”)
    #pragma comment(lib, “advapi32.lib”)
    #pragma comment(lib, “libcurl.lib”)

因为该配置在debug模式下可以正常运行,但切换到Release模式下就报错,并且确保配置时区分win32和x86平台。
针对该链接错误,总算找到解决方法,参考该链接:https://www.cnblogs.com/ytjjyy/archive/2012/05/19/2508803.html

解决方法:
添加预编译项:project–>Properties–>C/C+±->Preprocessor–>Preprocessor Definitions–>分别输入BUILDING_LIBCURL和HTTP_ONLY;

猜你喜欢

转载自blog.csdn.net/hanxiucaolss/article/details/88952200