Compilation of the Libcurl library

Source: Internet
Author: User
Tags install openssl openssl library

Finally understand the compilation of the Libcurl library, write down to avoid forgetting.

 libcurl Library: Http://curl.haxx.se/latest.cgi?curl=zip openssl installation package: http://slproweb.com/products/ win32openssl.html    NOTE: This after installation, in the installation directory, the corresponding  dll, include files and Lib files     Add OpenSSL library is to add Libcurl library pair HTTPS protocol support    compilation process: 1, choose compile version     compile different versions of Libcurl need to add different library support.         Unzip the Libcurl package and enter the  projects\windows\vc10\lib directory. Open Libcurl.sln      //your VC version number           Add OpenSSL support, select "DLL Debug-dll OpenSSL "version  2, add OpenSSL directory     download install OpenSSL directory     2.1, create a OpenSSL directory dependent on the Libcurl library, and copy the header file & nbsp;    View project Properties      Notice:   that is to say, we need to copy the Include/openssl folder from the OpenSSL directory to Curl compresses the package in the same sibling directory as the unpacked directory.     As for why the entire OpenSSL folder is copied over, instead of copying the files in the past, you can compile it first and note the file structure of the hint.      2.2, find Libeay32.lib and Ssleay32.lib files in Openssl/lib, copy to projects\windows\vc10\lib directory    &N Bsp As for why these two files are needed, check the properties/linker/input/attachment dependencies/, the two previous systems are brought in, and the following are the one we want to add. &nbSp; 3, compile, and use.     3.1, directly compiled to get the Libcurld.lib and libcurld.dll  we need           in \BUILD\WIN32\VC10 The corresponding version of the library can be found under the path.     3.2, using Libcurl library          3.2.1, adding dependent libraries to your project: additional dependencies, inputs, properties, and so on. Add the Libcurl.lib ws2_32.lib winmm.lib wldap32.lib
Note that the Debug configuration uses the Libcurld.lib
3.2.2, adding pre-compile Options: Project----Properties->c/c++, preprocessor---preprocessor, put; Building_libcurl; Http_only copy it in (be careful not to lose ";" ) 3.2.3, Libeay32.lib and Ssleay32.lib, Libcurld.lib copy to project. sln directory 3.2.4, Libeay32.dll and Ssleay32.dll, Libcurl D.dll Copy to run directory test code:
#include <iostream>#include<string>#include"curl/curl.h"using namespacestd;classcurlautorelease{ Public: Curlautorelease () {p=curl_easy_init ();} ~curlautorelease () {curl_easy_cleanup (P);} CURL*getptr () {returnp;}protected: CURL*p;}; UINT Curlwritebuffer (Char*buffer,uint size,uint NMEMB,STD::string*stream) {UINT sizes= size*Nmemb; if(stream = = NULL)return 0; Stream-append (buffer,sizes); returnsizes;}intMain () {curl_global_init (Curl_global_default); STD::stringSzurl ("www.baidu.com"); STD::stringSzcontent (""); Try{curlautorelease curlautorelease; CURL* Curl =curlautorelease.getptr ();        Curlcode Res; STD::stringstrresult;            {curl_easy_setopt (Curl,curlopt_url,szurl.c_str ()); Curl_easy_setopt (Curl,curlopt_verbose,1);//Turn on DebuggingCurl_easy_setopt (Curl,curlopt_postfields,szcontent.c_str ());//POST Requestcurl_easy_setopt (Curl,curlopt_postfieldsize,szcontent.length ());            Curl_easy_setopt (Curl,curlopt_writefunction,curlwritebuffer); //Write CallbackCurl_easy_setopt (Curl,curlopt_writedata,&strresult);//Write StorageCurl_easy_setopt (Curl,curlopt_timeout,Ten);//Maximum execution TimeRes=curl_easy_perform (Curl); }        if(Res! =CURLE_OK) {            //failed to post http Requesetstd::cout<<"failed to post HTTP request! "<<Std::endl; return-1; }        Else{std::cout<<strResult<<Std::endl; }    }    Catch (...) {        //out Exceptionstd::cout<<"Httprqworker::handletask appeared exception!!."<<Std::endl;    } curl_global_cleanup (); return 0;}

Compilation of the Libcurl library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.