curl 是以URL语法来传输输出的一个命令行工具。libcurl 是对对其功能的封装,实现了命令行工具的所有功能。
curl 支持HTTP、HTTPS、FTP、FTPS、DICT、TELNET、LDAP、FILE,和GOPHER协议。
libcurl 使用C语言编写。本文介绍在Linux,Windows的下的编译方法。这其中会用到cmake,gcc,visual c++ 2017(windows 下msvc方式编译)。
下载libcurl源码
从GitHub或者Gitee都有镜像可以下载。
git clone --depth=1 https://github.com/curl/curl.git
下载后libcurl 7.73.0
Linux下编译
- 生成configure
- 运行./configure
- make & make install
如果需要编译例子,可以执行如下命令
make test
windows下编译
配置OpenSSL
下载最新版本
git clone https://github.com/openssl/openssl.git
编译OpenSSL,按照文档NOTES-Windows要求,
- 安装Perl
- 安装NASM,并设置%PATH%路径
- 打开Cmd工具,配置VC编译环境,运行Visual Studio 里面的vcvarsall.bat, 选择要启动的编译环境例如:x86
- 运行命令perl Configure VC-WIN32(编译32位 OpenSSL)
- 执行nmake
- nmake install
编译输出库
命令行进入Curl源码文件夹:
cd curl-src\winbuild
执行命令 nmake /f Makefile.vc
,如果要输出到The builds will be in the top src directory, builds\
directory, in
a directory named using the options given to the nmake call.
nmake /f Makefile.vc mode=<static or dll> <options>
options:
- `VC=<6,7,8,9,10,11,12,14,15>` - VC version
- `SSL_PATH=<path>` - Custom path for OpenSSL
- `WITH_SSL=<dll/static>` - Enable OpenSSL support, DLL or static