- Libcurl main function is to use different protocols to connect and communicate with different servers, if using HTTPS, the need for OpenSSL
- Libcurl https://curl.haxx.se/download.html Download the source archives
- ActiveState https://www.activestate.com/activeperl/downloads to download the Perl parser, compile OpenSSL needs to be used.
- OpenSSL https://www.openssl.org/source/download openssl-1.0.2k,1.1.0 after the file and installation methods are changed.
- zlib http://zlib.net/Download a version other than 1.2.7, such as 1.2.11.
Extract
To facilitate installation, create a new folder named Libcurl-ssl in the D-Packing directory and extract the downloaded three compressed packages to the folder.
Create a new folder under curl-7.54.0-I OpenSSL is used to store the header file for OpenSSL.
Zlib Compile:
- Zlib-1.2.11\contrib\vstudio\vc14\zlibvc.sln, compile release version.
- There are Zlibwapi.dll and Zlibwapi.lib files in the generated X86\zlibdllrelease folder
ActiveState Installation:
Open the installation package, select Modify default installation or repair modify the installation path to
OpenSSL compilation:
This is the most troublesome and error-prone link because he has no project files and can only be compiled from the command line.
- Find the VS VS2015 x86 native tools command Prompt in the Start menu
- Use the CD command to go to the openssl-1.0.2k folder
- Command line type Perl Configure vc-win32 no-asm
- Command line type Ms\do_ms.bat
- Command line type Nmake-f Ms/ntdll.mak
Wait for almost five minutes, as long as the "stop" does not appear, safe execution to the end, even if successful.
Once there is a mistake in the middle, it is best to delete the folder, re-unzip, configure the compilation, if you leave the compilation of the failed semi-finished, it may tell you "Cannot parse xxx".
The Libeay32.lib, Libeay32.dll, Ssleay32.lib, Out32dll of openssl-1.0.2k, Inc32, and openssl-1.0.2k, Ssleay32.dll together to the curl-7.54.0, Lib, and OpenSSL
Libcurl Compile:
Compile platform selection DLL Debug-dll OpenSSL
- curl-7.54.0->projects, Windows---VC14, Curl-all.sln, you may be prompted to upgrade the project, OK.
- Set Libcurl as the Startup project, select Libcurl, Resource files, and libcurl.rc, right-click "Move Out", which records the version information, will only increase the file, you can move out.
- Select the preprocessor definition, C + + +, properties, and then change "Building_libcurl" to "Curl_staticlib". That way, those interface functions are not declared as export functions.
- Select Properties---linker---Add additional Library directories: \.. \.. \.. \lib\openssl, to Curl-7.54.0, Lib, and OpenSSL
- Select Properties, linker, input, and additional dependencies add libeay32.lib;ssleay32.lib;ws2_32.lib;wldap32.lib; The first two are for OpenSSL, and the latter two are for curl to depend on.
Libcurld.dll and Libcurld.lib are generated in the DLL debug-dll OpenSSL folder, curl-7.54.0, build, Win32, VC14, after compilation is successful (note The meaning of the name is not libcurl).
To create a console application
For example, the created project folder is located in D:-Libcurltest, and the compiled version is debug X86.
- Create a new libcurltest. Include folder, and copy the past with the Curl folder under the Include directory, curl-7.54.0.
- Create a new libcurltest. lib folder and create a new debug folder under Lib. Copy the Libcurl compiled Libcurld.dll and libcurld.lib to debug.
- Libcurld.dll and previous OpenSSL generated Libeay32.dll, ssleay32.dll each copy to the project folder, or will report an error.
- Select the preprocessor definition, c\c++, configuration Properties, and add Curl_staticlib.
- The additional Include directories, additional library directories, and additional dependencies in the properties are implemented in the code.
Test code
#include "stdafx.h"
#include "../include/curl/curl.h"
#pragma comment(lib,"../lib/debug/libcurld.lib")
int main()
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, true);
curl_easy_setopt(curl, CURLOPT_URL, "https://www.baidu.com");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
system("pause");
return 0;
}
Running results: The https://www.baidu.com Web page source is displayed in the console, and HTTPS cannot be accessed without the compile and link of OpenSSL. But the display Chinese part is garbled, I level limited, think this is C + + output problem, I will save the source to txt open is no problem.
Note: This document is organized and modified from the Internet.
Richard
Links: http://www.jianshu.com/p/2a92e1f30d0c
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Windows compilation Libcurl (Openssl+zlib) (compiled with VC)