libcurl-7.54.1 additional zlib1.2.11 Compilation

Source: Internet
Author: User

There is a small program on hand to communicate through the HTTP protocol, select the famous libcurl as a support library. Because the online tutorial is more command-line compilation, I have a bad memory, I hate to remember a bunch of commands, so toss a day through vs to Libcurl and Zlib compiled. The following will record the compilation process as a memo.
I. Environment and library version Introduction
WIN10 64-bit, vs_professional_2013_with_update_5, curl-7.54.1, zlib-1.2.11
Second, the purpose
Generate Libcurl static libraries and support for use under XP
Third, start
1. Compiling zlib
Download zlib-1.2.11 and unzip from http://www.zlib.net/, go to Catalog ZLIB-1.2.11\CONTRIB\VSTUDIO\VC12 open project, select Zlibstat Project, set properties-- Releasewithoutasm-> General, Platform toolset->visual Studio 2013-windows XP (V120_XP), character set my project is all Unicode, so this place is also set to Unicode. If you choose Release compilation, you need to compile the ASM code First, you can refer to the Zlib tutorial I wrote earlier (1, lib-1.2.8 compilation from http://www.zlib.net/download zlib-1.2.8.tar.gz, extract to directory zlib-1.2.8; vs2008 command line into zlib-1.2.8\contrib\ Masmx86 directory, execute bld_ml32.bat, enter directory Zlib-1.2.8\contrib\vstudio, compile 4, Static link library Zlibstat.lib use the introduction header file Zlib.h, add #pragma comment ( LIB, "Zlibstat.lib"), prompts for error LNK2019 when used: unresolved external symbols _inflateend,error LNK2019: unresolved external symbols _inflate, etc, when people are very depressed, A long study to find the need to introduce a header file zlib.h before adding a # define ZLIB_WINAPI, Ye. zlib Static link library requires only 2 header files, zconf.h and Zlib.h
2. Compiling Libcurl
Download libcurl-7.54.1 and unzip from https://curl.haxx.se/libcurl/, go to Catalog CURL-7.54.1\PROJECTS\WINDOWS\VC12 open project, select Libcurl Project, New configuration through Configuration Manager, in order to be easy to understand, I named Lib Release-dll WIN Sspi-dll winidn-lib zlib to Lib Release-dll Windows Sspi-dll winidn as a template, joined SSPI can support the role of https,winidn I don't know yet.
Select Libcurl Project, set properties->lib release-dll WIN sspi-dll winidn-lib zlib-> General, Platform toolset->visual Studio 2013-windows XP (V120_XP), character set Unicode. c/c++-> preprocessor---preprocessor definition increaseHave_zlib_h; Have_libz; Zlib_winapi。 C/c++-> General, additional Include directories add zlib.h and Zconf.h directories (recommended to copy the Lib, zlib.h, and zconf.h files from the previous step to a dedicated folder) general, library Manager Set Additional library directories and additional dependencies Zlibstat.lib (the Lib file name that was generated in the previous step).
Compile, libcurl.res:fatal error LNK1241: The resource file Zlibstat.lib (zlib.res) error has been specified because both the Libcurl project and the Zlib project have the resource version added. The workaround is to open the Solution Explorer to remove zlib.rc and recompile when you compile zlib in the previous step. Compile Libcurl again, get it done.
Iv. Use of Libcurl
Introduce header file, add Curl_staticlib macro
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Wldap32.lib")
#pragma comment (lib, "Crypt32.lib")
#pragma comment (lib, "Normaliz.lib")
#pragma comment (lib, "Libcurl.lib")

As for the compile time, the MD MT MDD MTD should be self-consistent
A lot of online tutorials, I only record a few of the content of the information.
Some web pages in the transmission, regardless of whether the client support compression is compressed transmission, directly from the Web to obtain the source of the Web page, the resulting compression code, we can decode themselves, you can also let Libcurl from the completion, the above is written to add zlib is to be automatically decoded.
Automatic decoding can be done via curl_easy_setopt (Curl_, curlopt_accept_encoding, "gzip"); In addition to gzip and other coding methods, I have a bad memory, can not remember anything else.
Libcurl The simplest steps to use (start by copying what others have summed up here, thank the original author):
curl* Curl=curl_easy_init ();
Curl_easy_setopt (Curl, Curlopt_url, "http://www.baidu.com");
Curl_easy_perform (curl);
Curl_easy_cleanup (curl);
Curl_global_cleanup ();
On multi-threading, you should curl_global_init in the beginning of the program, then create individual threads, use Curl_easy_init in each thread to create the handle of curl, and then use curl_easy_setopt for this handle ( handle, XXX, XXX) Set the various parameters of the transmission, and finally use Cur_easy_perform (handle) to perform the action, after the transmission is over, finally call Curl_easy_cleanup (handle) to release, Then end the thread in the main thread of the program, and when all the threads are finished, call Curl_global_cleanup to end Libcurl before the program exits.

libcurl-7.54.1 additional zlib1.2.11 Compilation

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.