交叉编译curl并支持http2

版权声明:原创文章未经同意,禁止转载 https://blog.csdn.net/zmlovelx/article/details/86617920

下载nghttp2代码
https://github.com/nghttp2/nghttp2/releases
解压代码, 比如解压到/home/zm/download/nghttp2-1.36.0,进入代码目录,进行编译
./configure --enable-lib-only --host=arm-openwrt-linux --prefix=/opt/test/thirdparty/install/
make
make install

下载curl代码
https://curl.haxx.se/download.html
或者
https://curl.haxx.se/download/?C=M;O=D
解压后,进入代码目录

假设其他的依赖库放在/opt/test/thirdparty/install/下,包括ssl cares 等库
生成Makefile
PKG_CONFIG_PATH="/opt/test/thirdparty/install/lib/pkgconfig" \
./configure --host=arm-openwrt-linux --enable-ares --enable-http --enable-ipv6 --enable-pthreads --enable-cookies --with-nghttp2=/opt/test/thirdparty/install  CPPFLAGS="-I/opt/test/thirdparty/install/include"  LDFLAGS="-L/opt/test/thirdparty/install/lib" LIBS="-L/opt/test/thirdparty/install/lib" --prefix=`pwd`/install

修改Makefile
src/Makefile
1) CCLD = $(CC) 改成 CCLD = $(CC) $(LIBCURL_LIBS)
不改CCLD会出现
../lib/.libs/libcurl.so: undefined reference to `EVP_MD_CTX_free@OPENSSL_1_1_0'
../lib/.libs/libcurl.so: undefined reference to `X509_EXTENSION_get_object@OPENSSL_1_1_0'
的错误

curl-7.62.0后,Makefile中没有 CCLD,则可以在生成Makefile时把IBS="-L/opt/test/thirdparty/install/lib" 改成

IBS="-L/opt/test/thirdparty/install/lib -lcares -lnghttp2 -lssl -lcrypto -lz"

改完后开始编译:
make
make install

测试是否支持http2
curl -v -k --http2 https://www.xdty.org

如果打印如下说明编译出来的curl不支持http2
curl: (1) Unsupported protocol

以下为正常的打印
root@(none):/# curl -v -k --http2 https://www.xdty.org
*   Trying 54.95.68.178...
* TCP_NODELAY set
* Connected to www.xdty.org (54.95.68.178) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=xdty.org
*  start date: Dec 14 10:16:39 2018 GMT
*  expire date: Mar 14 10:16:39 2019 GMT
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x79e788)
> GET / HTTP/2
> Host: www.xdty.org
> User-Agent: curl/7.63.0
> Accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 200

作者:帅得不敢出门   c++哈哈堂:31843264
 

猜你喜欢

转载自blog.csdn.net/zmlovelx/article/details/86617920