最近项目中要用到libcurl库,配置了一下这个库。
1、下载libcurl
win32版的libcurl下载地址:
不带ssl的:http://curl.haxx.se/download/libcurl-7.18.0-win32-msvc.zip
带ssl的:http://curl.haxx.se/download/libcurl-7.19.3-win32-ssl-msvc.zip
这是编译好的库。直接使用
2、添加VS的目录
把下载的压缩包解压某个目录,在VS中把lib, include目录添加上,把目录**/, **/lib/debug, **/lib/release下的dll文件拷贝到工程中的debug,release目录下。
引入lib文件:使用方法为,注意还有debug和Release两种库 :
//不带SSL
#pragma comment(lib, "libcurl.lib")
//带SSL
#pragma comment(lib, "libcurl_imp.lib")
3、test.cpp
#include <curl/curl.h>
#pragma comment (lib , "curllib.lib" )
int main(int argc, char *argv[])
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL , "http://www.baidu.com");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
system( "pause");
}