我正在尝试使用 visual studio 2015 静态链接一个小型测试 curl 程序,但我无法正确链接它。
我使用这个批处理文件编译成功的 curl https://github.com/blackrosezy/build-libcurl-windows
然后我将 libcurl 目录复制到我的项目目录中,我的代码如下
#include "stdafx.h"
#include "libcurl/include/curl/curl.h"
#pragma comment(lib, "libcurl/lib/static-debug-x64/libcurl_a_debug.lib")
#define CURL_STATICLIB
int main()
{
curl_global_init(CURL_GLOBAL_DEFAULT);
CURL *curl = curl_easy_init();
if (curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
printf("Press any key to continue\n");
getchar();
return 0;
}
但是无论我做什么,我都无法让我的链接器不再这样做:
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_global_init referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_global_cleanup referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_setopt referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_perform referenced in function main
1>CurlTest.obj : error LNK2019: unresolved external symbol __imp_curl_easy_cleanup referenced in function main
1>U:\Main\Code\CurlTest\x64\Debug\CurlTest.exe : fatal error LNK1120: 6 unresolved externals
我已确认所有这些路径均有效,并尝试使用调试和发布库,以及 32 位和 64 位(在 visual studio 中使用匹配设置)。这将使用非静态库进行编译,但这是废话,因为我只想分发我的 .exe 而不是 dll。
我在这里做错了什么?这非常令人沮丧,从我从类似线程中读到的#define CURL_STATICLIB 指令应该纠正这种行为来看,它看起来只是幼稚。
最佳答案
#pragma comment(lib, "wldap32.lib" )
#pragma comment(lib, "crypt32.lib" )
#pragma comment(lib, "Ws2_32.lib")
#define CURL_STATICLIB
#include <curl/curl.h>
这使它对我有用。
希望对您有所帮助,问候。
关于c++ - Visual Studio 2015 curl 不会静态链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41762859/