1. 下载和编译 boringssl
$ git clone https://boringssl.googlesource.com/boringssl
$ cd boringssl
$ mkdir build
$ cd build
$ cmake ..
$ make
编译前需要安装 cmake,zlib,go等软件:
sudo apt-get install -y build-essential
sudo apt-get install cmake zlib1g-dev
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update
sudo apt-get install golang-go
boringssl编译完成后,为方便 curl 引用头文件和库文件,需要在源码根目录创建lib目录,将build目录下生成的libssl.a和 libcrypto.a创建个软链接到lib目录。
cd <src根目录>
mkdir lib
cd lib
ln -s ../build/ssl/libssl.a
ln -s ../build/crypto/libcrypto.a
2. 下载和编译 curl
wget https://curl.haxx.se/download/curl-7.70.0.tar.gz
tar xzfv curl-7.70.0.tar.gz
cd curl-7.70.0
./configure --with-ssl=/home/zhb/crypto/boringssl-master
make
下面就是成功配置的信息:
Host setup: x86_64-pc-linux-gnu
Install prefix: /usr/local
Compiler: gcc
CFLAGS: -Werror-implicit-function-declaration -O2 -Wno-system-headers
CPPFLAGS: -isystem /home/zhb/crypto/boringssl-master/include/openssl -isystem /home/zhb/crypto/boringssl-master/include
LDFLAGS: -L/home/zhb/crypto/boringssl-master/lib
LIBS: -lssl -lz -lcrypto -ldl -lpthread
curl version: 7.70.0
SSL: enabled (BoringSSL)
SSH: no (--with-{libssh,libssh2})
zlib: enabled
brotli: no (--with-brotli)
GSS-API: no (--with-gssapi)
TLS-SRP: no (--enable-tls-srp)
resolver: POSIX threaded
IPv6: enabled
Unix sockets: enabled
IDN: no (--with-{libidn2,winidn})
Build libcurl: Shared=yes, Static=yes
Built-in manual: enabled
--libcurl option: enabled (--disable-libcurl-option)
Verbose errors: enabled (--disable-verbose)
Code coverage: disabled
SSPI: no (--enable-sspi)
ca cert bundle: /etc/ssl/certs/ca-certificates.crt
ca cert path: no
ca fallback: no
LDAP: no (--enable-ldap / --with-ldap-lib / --with-lber-lib)
LDAPS: no (--enable-ldaps)
RTSP: enabled
RTMP: no (--with-librtmp)
Metalink: no (--with-libmetalink)
PSL: no (libpsl not found)
Alt-svc: no (--enable-alt-svc)
HTTP2: disabled (--with-nghttp2)
HTTP3: disabled (--with-ngtcp2, --with-quiche)
ESNI: no (--enable-esni)
Protocols: DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP
Features: SSL IPv6 UnixSockets AsynchDNS NTLM NTLM_WB HTTPS-proxy
编译错误,环境:windows 环境 Ubuntu18.1
/usr/bin/ld: /home/zhb/crypto/boringssl-master/lib/libcrypto.a(bcm.c.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:1237: recipe for target 'libcurl.la' failed
解决办法:这是因为引用的 boringssl 库编译时没有添加 -fPIC 标志所致,加上这个标志,重新编译boringssl。
修改 boringssl-master根目录下的 CMakeLists.txt 添加 -fPIC 到 gcc 编译选项:
if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
# Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration
# primarily on our normal Clang one.
set(C_CXX_FLAGS "-fPIC -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings -Wvla")
然后重新编译boringssl:
cd boringssl-master/build
rm -rf *
cmake ..
make
再重新编译curl,编译就OK了,然后 sudo make install 安装curl。
执行的时候发现这个错误:
$ curl
curl: symbol lookup error: curl: undefined symbol: curl_multi_poll
网上查了下发现 curl_multi_poll 是 7.66.0新添加的功能:
curl_multi_poll是新增加的全新函数,其行为与curl_multi_wait非常相似,但是有一个主要好处:它解决了应用程序在libcurl在文件描述符耗尽的情况下,继续等待避免由此导致问题。
找了半天也不知道怎么解决,只好去先下载一个 7.65.3 版本。
https://curl.haxx.se/download/curl-7.65.3.tar.gz