libcurl的编译及使用

来源:互联网 发布:约爱cms源码程序.zip 编辑:程序博客网 时间:2024/06/05 08:56

最新版本请在下载:https://curl.haxx.se/download.html
下载完成后,编译源码,官方下载的是需要自己编译的,我这里使用VS2013编译。
选择最基本的,如果需要带SSL,则需要自己下载openssl。否则无法编译。
然后就可以使用到自己的项目之中了。。。
基本示例:

#include "stdafx.h"#include "curl\curl.h"#include <WinSock2.h>#include <Windows.h>#include <wincrypt.h>#include <iostream>#pragma comment ( lib, "ws2_32.lib")#pragma comment ( lib, "wldap32.lib")#pragma comment (lib, "crypt32.lib")#ifdef _DEBUG#pragma comment(lib,"libcurld.lib")#else#pragma comment(lib,"libcurl.lib")#endifint _tmain(int argc, _TCHAR* argv[]){    CURL* curl = curl_easy_init();    if (curl == NULL)    {        cout << "init fail!" << endl;    }    curl_easy_setopt(curl, CURLOPT_URL, "https://www.xxxxx.com/");    res = curl_easy_perform(curl);    curl_easy_cleanup(curl);    system("pause");    return 0;}

其中几个lib库是必须的,否则编译不通过。
预处理器定义:

CURL_STATICLIB//这里去除编译警告_CRT_SECURE_NO_WARNINGS
0 0