在没有dll的情况下使用libcURL的正确方法是什么?
What's the proper way of using libcURL without the dlls?
最近成功地在一个测试程序中使用了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在常见问题解答中说:
当构建使用静态libcurl库的应用程序时,必须将
-DCURL_STATICLIB
添加到CFLAGS
中。否则,链接器将查找动态导入符号。如果您使用的是Visual Studio,则需要在"预处理器定义"部分添加CURL_STATICLIB
。
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);
}
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 通过JNI传递数据数组的最快方法是什么
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 使用不同的CRT将新的C++代码与旧的(二进制)组件隔离开来的最佳方法是什么
- 当无法使用模板和宏时,生成类型变体C++代码的最简单方法是什么?
- 在另一个类视图中添加最多2个图表的正确方法是什么
- 在C++中样板"冷/never_inline"错误处理技术的最佳方法是什么?
- 在 c++ 中对类中的 c 字符串动态数组进行排序的最佳方法是什么?
- 在C++中包含原型文件的正确方法是什么?
- 在 OpenCV C++ 中估计基本矩阵之前对相应点进行归一化的正确方法是什么?
- 在PostgreSQL中根据它们的ID选择大量行的最快方法是什么?
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- 将一系列整数放入类的最佳方法是什么?
- 从长整整转换为uint64_t的推荐方法是什么?
- 将此布尔值传递给此函数的最有效方法是什么?
- 通过比较C++中的行在 txt 文件中搜索的最简单方法是什么?