最近设法在测试程序中使用 libcurl 来下载文件。
代码是这样的:
CURL * curl;
FILE * fout;
CURLcode result;
char * url = "http://blablabla.com/blablabla.txt";
char filename[FILENAME_MAX] = "blablabla.txt";
curl = curl_easy_init();
if (curl)
{
fout = fopen(filename,"wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fout);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fout);
}
以及指令的那些东西:
#define CURL_STATICLIB
#include <curl/curl.h>
我的问题是如何使我不需要将其所有 dll 复制到与 exec 相同的目录中以使其工作:
libcurl.dll
libeay32.dll
libidn-11.dll
librtmp.dll
libssh2.dll
libssl32.dll
zlib1.dll
在图书馆的主页 (http://curl.haxx.se) 中找不到相关信息:|
请您参考如下方法:
你的意思是,“我如何静态链接 libcurl”?
5.7 中 FAQ说:
When building an application that uses the static libcurl library, you must add
-DCURL_STATICLIB
to yourCFLAGS
. Otherwise the linker will look for dynamic import symbols. If you're using Visual Studio, you need to instead addCURL_STATICLIB
in the "Preprocessor Definitions" section.