vs2017 compiling and configuring Libcurl Getting Started Tutorial

Source: Internet
Author: User

Libcurl can be used to send HTTP requests, which are common libraries for C/E + + send HTTP requests

Download Libcurl Source Package:

Libcurl:https://curl.haxx.se/download.html

Unzip to
C:\source\repos\libcurl\curl-7.60.0

Open the Curl folder and run Buildconf.bat with administrator privileges.

Compiling Libcurl source code

Select "Start"->[visual Studio 2017]->[visual Studio tools]->[vc]->[x64 Native Tools Command Prompt for VS 2017]

After opening, go to get the corresponding Curl directory

cd C:\source\repos\libcurl\curl-7.60.0\winbuild

VS2017 x64 Static compilation

Enter the following command, and then enter to start compiling

nmake /f Makefile.vc mode=static VC=14 MACHINE=x64 DEBUG=no

Description of the compilation options:
If you want to use dynamic compilation, change the mode=static to Mode=dll. (This article teaches static compilation only, and curl is not recommended to use dynamic compilation)
If you use x86, change machine=x64 to Machine=x86.
If you need a debug version, change the Debug=no to Debug=yes.
More detailed compilation instructions and instructions can open the BUILD.WINDOWS.txt view in the Winbuild folder.

A few minutes can be compiled to the end (i5-3470 CPU 3.2GHz, 8G memory, 7200 RPM mechanical hard disk).

To finish compiling, close the console interface.
Open the Builds folder in the C:\source\repos\libcurl\curl-7.60.0\ folder and back up the shortest folder (if both x64 and x86 are compiled, you need to back up the two least-named folders). The Curl folder can be deleted if there is no other need.

Configuring VS2017 Engineering

Copy the C:\source\repos\libcurl\curl-7.60.0\builds\ generated above The Include and Lib directories under Libcurl-vc15-x64-release-static-ipv6-sspi-winssl to the C # root directory

1. Open VS2017, create a new project Testcurl,select [File]->[newproject]->[visual c++]->[windows desktop]->[windows Console Application]

2. Right-click the project, select Properties, select [Configurations] to select release

3.[platform] Select x64 to confirm that the release is selected at compile time, x64

4. Add the Include folder and the Lib folder in the folder you just compiled to the project. (If Debug version libcurl is compiled, the contents of the Debug folder should be added to the Debug Configuration project)

[Configuration properties]->[vc++ directories], select Edit

4.1[include directories] Added C:\include

4.2[library directories] Added C:\lib

5. The static compilation Libcurl is used, so the curl_staticlib needs to be added to the project

[Configuration properties]->[c/c++]->[preprocessor], select Edit
New curl_staticlib;

6. Confirm that the [configuration Properties]->[c/c++]->[code generation]->[runtime Library] is set to "multi-threaded DLL (/MD)"
If you do not compile the debug version of Libcurl, you will need to change the Runtime Library to release version (i.e. without the lowercase letter D). It is also not recommended to use "/MT" or "/MTD".

7.[configuration properties]->[additional Dependencies] added Libcurl_a.lib

8. Enter the following test code generated by postman, Postman is a very useful debugging HTTP interface tool, it is recommended to learn briefly:

#include "stdafx.h"//need the following library to pass build, why do you need it and study it later?#pragma comment (lib, "Ws2_32.lib")#pragma comment (lib, "Wldap32.lib")#pragma comment (lib, "Crypt32.lib")#include <curl/curl.h>#include <stdio.h>using namespaceStdintMainvoid){//InitializeCURL *hnd = Curl_easy_init (); Curl_easy_setopt (HND, Curlopt_customrequest,"POST"); Curl_easy_setopt (HND, Curlopt_url,"Http://193.28.51.120:8002/api/account/validtoken");structCurl_slist *headers = NULL; headers = curl_slist_append (headers,"Authorization:bearer I am a login token"); headers = curl_slist_append (headers,"Content-type:application/json"); headers = curl_slist_append (headers,"Accept:application/json");    Curl_easy_setopt (HND, Curlopt_httpheader, headers); Curl_easy_setopt (HND, Curlopt_postfields,"{\"userId\": \"43000010\"}");    Curlcode ret = Curl_easy_perform (HND); printf"Ret0:%d\n", ret); LONG Nhttpcode =0;//Remove HTTP Return status code (200 for success)ret = Curl_easy_getinfo (HND, Curlinfo_response_code, &nhttpcode); printf"Ret1:%d\n", ret); printf"Nhttpcode:%d\n", Nhttpcode);//Recycling ResourcesCurl_easy_cleanup (HND);return 0;}

Reference:
79851039

77587916

vs2017 compiling and configuring Libcurl Getting Started Tutorial

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.