最近设法在测试程序中使用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>
我的问题是如何使我不需要在exec的同一目录中复制它的所有dll以使其工作:
libcurl.dll
libeay32.dll
libidn-11.dll
librtmp.dll
libssh2.dll
libssl32.dll
zlib1.dll
在图书馆的主页(http://curl.haxx.se)中找不到相关信息:|
答案 0 :(得分:10)
你的意思是“我如何静态链接libcurl”?
FAQ中的5.7说:
构建使用静态libcurl库的应用程序时,必须将
-DCURL_STATICLIB
添加到CFLAGS
。否则,链接器将查找动态导入符号。如果您使用的是Visual Studio,则需要在“预处理器定义”部分中添加CURL_STATICLIB
。
答案 1 :(得分:-3)
CURL *curl;
CURLcode res;
CString strUser;
FILE *ftplister;
m_FTPUserName.GetWindowTextW (strUser);
CT2CA PUF_File_HostName(PUF_FIle_Host);
CT2CA FTP_UserName(FTP_USERNAME);
FTP_PASSWORD.Append(L":");
FTP_PASSWORD.Append(FTP_USERNAME);
CT2CA FTP_Password(FTP_PASSWORD);
CT2CA FTP_AddressName(FTP_Address);
CString strLocalFile;
CString strFileName;
m_FTPFileName.GetWindowTextW(strFileName);
strLocalFile.Append(FTP_FileName);
strLocalFile.Append(L"\\");
strLocalFile.Append(strFileName);
CT2CA PUF_LocalFile(strLocalFile);
//ofstream stream2(PUF_LocalFile);
curl = curl_easy_init();
if(curl)
{
ftplister=fopen(PUF_LocalFile,"wb");
curl_easy_setopt(curl,CURLOPT_URL,PUF_File_HostName);
if(strUser!=_T(""))
{
curl_easy_setopt(curl,CURLOPT_USERPWD,FTP_Password);
}
curl_easy_setopt(curl, CURLOPT_FTP_SSL, TRUE);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftplister);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(ftplister);
}