【libcurl】Visual Studio 2017编译和配置libcurl开发环境

一、libcurl介绍
libcurl是免费的客户端URL传输库,支持DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP。libcurl支持SSL证书, HTTP POST、HTTP PUT、FTP上传、基于HTTP表单的上传、代理、Cookie、用户+口令认证(基本、摘要、NTLM、协商、Kerberos)、文件续传、HTTP代理隧道等!php

libcurl是高度可移植的,它构建和工做在许多平台上,包括Solaris、NETBSD、FreeBSD、OpenBSD、Darwin、HPUX、IIX、AIX、TUR6四、Linux、UNIX、HUD、Windows、AMIGA、OS/二、BeOs、Mac OS X、ULTRIX、QNX、OpenVMS、RISC OS、Novell NETWORD、DOS等等。html

libcurl是免费的,线程安全,IpV6兼容,功能丰富,良好支撑,快速,文档全面,并已被许多知名的,大的和成功的公司使用。c++

主页地址:https://curl.haxx.se/libcurl/windows

二、环境
Windows 10(1803)
Visual Studio 2017(15.7.3)
三、编译libcurl
下载libcurl,地址:https://curl.haxx.se/download.html 
我使用的是curl-7.60.0。 安全


解压文件,进入目录curl-7.60.0,运行buildconf.batcurl

进入curl-7.60.0目录下的winbuild目录,复制路径
进行x64编译 
在开始菜单中找到Visual Studio 2017文件夹,选择以下: 
 
打开命令窗口以下: 测试

在命令窗口输入以下命令:fetch

cd D:\ThirdCode\curl-7.60.0\winbuild #根据本身的路径输入
d:
nmake /f Makefile.vc mode=static VC=14 MACHINE=x64 DEBUG=no
1
2
3
我设置的是在vc14下静态release编译。 
编译参数设置根据winbuild目录下BUILD.WINDOWS.txt自行设置,具体参数以下:ui

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

where <options> is one or many of:
  VC=<6,7,8,9,10,11,12,14,15>    - 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_NGHTTP2=<dll or static>   - Enable HTTP/2 support, DLL or static
  WITH_MBEDTLS=<dll or static>   - Enable mbedTLS 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
  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)
  CARES_PATH=<path to cares>     - Custom path for c-ares
  MBEDTLS_PATH=<path to mbedTLS> - Custom path for mbedTLS
  NGHTTP2_PATH=<path to HTTP/2>  - Custom path for nghttp2
  SSH2_PATH=<path to libSSH2>    - Custom path for libSSH2
  SSL_PATH=<path to OpenSSL>     - Custom path for OpenSSL
  ZLIB_PATH=<path to zlib>       - Custom path for zlib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
等待编译结束后,关闭命令窗口。 
编译后的头、静态文件等见curl-7.60.0目录下builds目录 


四、在Visual Studio 2017中使用
建立vc++项目
把前面编译的lib和include目录添加至项目,以下 

把libcurl_a.lib、ws2_32.lib、winmm.lib、wldap32.lib、Crypt32.lib、Normaliz.lib添加至项目,以下 

预处理器定义添加CURL_STATICLIB;_CRT_SECURE_NO_WARNINGS 

运行库设置 

运行例子  测试例子:https://curl.haxx.se/libcurl/c/fileupload.html  例子中须要修改  CURLINFO_TOTAL_TIME_T(适用curl-7.60.1版本) 改成 CURLINFO_TOTAL_TIME。  注意修改下图红框内容  第一红框中为本地文件路径(例如:D:/TestData/1骄傲.mp3);  第二红框中为目的文件路径(例如:file:///e:/1骄傲.mp3); 

相关文章
相关标签/搜索