【libcurl】Visual Studio 2017编译和配置libcurl开发环境
1、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代理隧道等!
libcurl是高度可移植的,它构建和工作在许多平台上,包括Solaris、NETBSD、FreeBSD、OpenBSD、Darwin、HPUX、IIX、AIX、TUR64、Linux、UNIX、HUD、Windows、AMIGA、OS/2、BeOs、Mac OS X、ULTRIX、QNX、OpenVMS、RISC OS、Novell NETWORD、DOS等等。
libcurl是免费的,线程安全,IpV6兼容,功能丰富,良好支撑,快速,文档全面,并已被许多知名的,大的和成功的公司使用。
主页地址:https://curl.haxx.se/libcurl/
2、环境
- Windows 10(1803)
- Visual Studio 2017(15.7.3)
3、编译libcurl
下载libcurl,地址:https://curl.haxx.se/download.html
我使用的是curl-7.60.0。解压文件,进入目录curl-7.60.0,运行buildconf.bat
- 进入curl-7.60.0目录下的winbuild目录,复制路径
-
进行x64编译
在开始菜单中找到Visual Studio 2017文件夹,选择如下:
打开命令窗口如下:
在命令窗口输入如下命令:cd D:\ThirdCode\curl-7.60.0\winbuild #根据自己的路径输入 d: nmake /f Makefile.vc mode=static VC=14 MACHINE=x64 DEBUG=no
我设置的是在vc14下静态release编译。
编译参数设置根据winbuild目录下BUILD.WINDOWS.txt自行设置,具体参数如下: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,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
等待编译结束后,关闭命令窗口。
编译后的头、静态文件等见curl-7.60.0目录下builds目录
4、在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);
推荐阅读
-
Visual Studio Code (VSCode) 配置搭建 C/C++ 开发编译环境的流程
-
【libcurl】Visual Studio 2017编译和配置libcurl开发环境
-
基于WIN10系统的OpenCV3.4.0+Python2.7+Visual Studio 2017编译开发环境搭建
-
OpenCV 3.4.1在windows 10 64位和Microsoft Visual Studio 2017下的安装与环境配置
-
Visual Studio(VS2017)配置C/C++ PostgreSQL9.6.3开发环境
-
Visual Studio Code (VSCode) 配置搭建 C/C++ 开发编译环境的流程
-
Visual Studio配置:vs 2017配置FFmpeg开发环境配置
-
opencv 3.0 + visual studio 2017 机器视觉开发环境配置
-
Microsoft Visual Studio 2017配置OpenCV开发环境简要操作
-
visual studio 2017 配置 opencv 3.2 开发环境