【发布时间】:2017-06-05 09:29:49
【问题描述】:
我正在尝试使用 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 指令应该纠正这种行为的内容看来,这看起来很幼稚。
【问题讨论】:
-
这有什么帮助?我使用的是 Windows 和 Visual Studio,而不是 gcc。
-
链接在概念上应该类似于 WinBloat。
标签: c++ curl visual-studio-2015 linker