Under windows, compile libcurl static library process that can access https

1. First compile the openssl static library

The vs2015 command prompt tool is used in the whole process

perl needs to be installed
Download address: Add link description
After unpacking, create the develop ep folder in the openssl-1.0.2e directory and cd it to the openssl-1.0.2e directory,

a. Configure compiled files and modes

perl Configure VC-WIN32 no-asm --prefix=E:\curl\openssl-1.0.2e\develop

VC-WIN32 identifies the windows 32-bit operating system,
64 bit is represented by VC-WIN64A. To use the debug version, please use debug-VC-WIN64A or debug-VC-WIN32
No ASM means no assembly
– prefix=E:\curl\openssl-1.0.2e\develop is the setup installation directory
b. Generate compilation configuration file
For Windows 64 bit system, execute


For Windows 32-bit system, execute


After performing this step, nt.exe will be generated in the ms directory Mak and ntdll Mak two compilation configuration files
nt.mak is used to generate static lib libraries
ntdll.mak is used to generate dynamic dll library
c. Compile
Static library

nmake -f ms\nt.mak	

Dynamic library

nmake -f ms\ntdll.mak

d. Testing
Test static library:

 nmake -f ms\nt.mak test

Test dynamic library:

 nmake -f ms\ntdll.mak test

If passed all tests is finally displayed, the generated library is correct
e. Installation
Install static library:

nmake -f ms\nt.mak install

Install dynamic library:

nmake -f ms\ntdll.mak install

After the compilation and installation is completed, you will see the generated relevant folders in the E: \ curl \ openssl-1.0.2e \ development directory
f. Clear about last compilation
Clear the compilation of the last static library for recompilation:

nmake -f ms\nt.mak clean

Clear the last compilation of dynamic library for recompilation:

nmake -f ms\ntdll.mak clean

reference resources: https://blog.csdn.net/mayue_web/article/details/83997969 , very detailed

2. Compile zlib

a. Download source code
After decompression, execute the command line under the zlib root directory
nmake -f win32/Makefile.msc

3. Compile libcurl

a. Download source code
b. Copy the required openssl and zlib related libraries and header files
. according to curl source code, the root directory is under the winbuild directory, and the root directory is under the build WINDOWS. Txt prompt
Create a deps folder in the directory at the same level of the source code
The directory structure at this time is shown in the following figure (pseudo directory)

|    |_winbuild
  |_ lib
  |_ include
  |_ bin

My deps folder directory here is E:\curl\deps
When OpenSSL will be compiled, the installation directory e: \ curl \ openssl-1.0.2e \ development \ include
Copy the openssl folder to E:\curl\deps\include \ directory;
Place the zlib source code in zconf.exe under the root directory h,zlib.h and zutil H copy to E:\curl\deps\include directory.
Put libeay32.0 in E:\curl\openssl-1.0.2e\develop\lib directory Lib and ssleay Copy lib to E:\curl\deps\lib directory;
Add zlib.exe in the root directory of zlib source code Copy lib to E:\curl\deps\lib directory.
c. Compile libcurl
The command line enters the winbuild directory under the root directory of the source code

nmake RTLIBCFG=static /f Makefile.vc mode=static VC=14 WITH_DEVEL=E:\curl\deps WITH_SSL=static ENABLE_SSPI=no ENABLE_IPV6=no DEBUG=no

The detailed meanings of parameters are as follows:

nmake /f Makefile.vc mode=<static or dll> <options>

where <options> is one or many of:
  VC=<6,7,8,9,10,11,12,14>     - VC versions
  WITH_DEVEL=<path>            - Paths for the development files (SSL, zlib, etc.)
                                 Defaults to sibbling directory deps: ../deps
                                 Libraries can be fetched at http://windows.php.net/downloads/php-sdk/deps/
                                 Uncompress them into the deps folder.
  WITH_SSL=<dll or static>     - Enable OpenSSL support, DLL or static
  WITH_CARES=<dll or static>   - Enable c-ares support, DLL or static
  WITH_ZLIB=<dll or static>    - Enable zlib support, DLL or static
  WITH_SSH2=<dll or static>    - Enable libSSH2 support, DLL or static
  ENABLE_SSPI=<yes or no>      - Enable SSPI support, defaults to yes
  ENABLE_IPV6=<yes or no>      - Enable IPv6, defaults to yes
  ENABLE_IDN=<yes or no>       - Enable use of Windows IDN APIs, defaults to yes
                                 Requires Windows Vista or later, or installation from:
  ENABLE_WINSSL=<yes or no>    - Enable native Windows SSL support, defaults to yes
  GEN_PDB=<yes or no>          - Generate Program Database (debug symbols for release build)
  DEBUG=<yes or no>            - Debug builds
  MACHINE=<x86 or x64>         - Target architecture (default is x86)
  Static linking of Microsoft's C RunTime (CRT):
If you are using mode=static nmake will create and link to the static build of
libcurl but *not* the static CRT. If you must you can force nmake to link in
the static CRT by passing RTLIBCFG=static. Typically you shouldn't use that
option, and nmake will default to the DLL CRT. RTLIBCFG is rarely used and
therefore rarely tested. When passing RTLIBCFG for a configuration that was
already built but not with that option, or if the option was specified
differently, you must destroy the build directory containing the configuration
so that nmake can build it from scratch.

Legacy Windows and SSL
When you build curl using the build files in this directory the default SSL
backend will be WinSSL (Windows SSPI, more specifically Schannel), the native
SSL library that comes with the Windows OS. WinSSL in Windows <= XP is not able
to connect to servers that no longer support the legacy handshakes and
algorithms used by those versions. If you will be using curl in one of those
earlier versions of Windows you should choose another SSL backend like OpenSSL.

3. Verification

After adding the included directory, the attached Library Directory and the attached dependencies, the preprocessor adds BUILDING_LIBCURL

// staticLibcurlTest.cpp: defines the entry point for the console application.

#include "stdafx.h"
#include <iostream>
#include <curl.h>

using namespace std;

* Once curl receives the data, it will call this callback function
* buffer:Data buffer pointer
* size:The debug phase is always found to be 1
* nmemb:(memory block)Represents the length of the memory block accepted this time
* userp:A user-defined parameter
size_t write_data(void* buffer, size_t size, size_t nmemb, void* userp)
	static int current_index = 0;

	cout << "current:" << current_index++;
	cout << (char*)buffer;
	cout << "---------------" << endl;

	int temp = *(int*)userp;    // Get user-defined parameters here
	return nmemb;

int main()
	curl_global_init(CURL_GLOBAL_ALL); // First, initialize the CURL globally
	CURL* curl = curl_easy_init(); // Initialize CURL handle

	if (NULL == curl)
		return 0;

	int my_param = 1;    // Customize a user parameter

						 // Set destination URL
	curl_easy_setopt(curl, CURLOPT_URL, "https://api.vxxx/gettime");
	// Set the callback function called when receiving data from the HTTP server
	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
	// Set custom parameters (the fourth parameter of callback function)
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &my_param);
	// Execute a URL request
	CURLcode res = curl_easy_perform(curl);
	// Clean up
	return 0;

reference resources:

Posted by anthonyv on Fri, 20 May 2022 20:45:28 +0300