boringssl + curl 編譯配置

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章