随笔:交叉编译libcurl库支持HTTPS

随笔:交叉编译libcurl库支持HTTPS

2017年09月03日 10:19:43 阅读数:2752 标签: 交叉编译 更多

个人分类: 交叉编译库

提供:

openssl和libcurl库百度云链接:
https://pan.baidu.com/s/1ge2ZkMB
提取码:h29q

目的:

需要的编译结果:mips下的libcurl库支持HTTPS
关键:libcurl库支持https协议,需要先编译安装openssl库

配置:

配置环境变量 sudo vim /etc/profile
最后一行添加以下内容:
PATH=/usr/local/arm/4.4.3/bin:$PATH
执行source /etc/profile
echo $PATH
多了一条自己添加的mips交叉编译工具链

/usr/local/mips/tool_chain/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
  • 1

mipsel-linux-uclibc-gcc -v
查看系统配置的编译工具

实战:

交叉编译libcurl时,直接运行./configure
这里写图片描述
如上图,看第五行,SSL support为no看最后一行,支持的协议中没有HTTPS,由此可知,我们编译出来的curl库并不支持https协议。

方案一:

./configure –with-ssl ( 加上ssl参数,因为默认./configure时没带该参数,所以导致编出来的curl库不支持https

ssl百度了下,全名Secure Socket Layer
如下图,协议支持HTTPS,SSL support 为enabled
这里写图片描述
解决了curl库支持HTTPS的问题,因为交叉编译的curl库需为mips平台的,命令./configure –with-ssl 交叉编译的库默认为x86平台。所以,我们加了参数,–host=mipsel-linux CC=tool_chain/bin/mipsel-linux-uclibc-gcc 。

那么,问题就来了
./configure –with-ssl –host=mipsel-linux CC=/usr/local/mips/tool_chain/bin/mipsel-linux-uclibc-gcc 一套完整的命令敲下去后,curl库为mips平台的,但是却又不支持HTTPS了(应该是我的openssl库为x86的,导致openssl和libcurl库不兼容)。
怎么办呢?看configure配置文件,如下图
这里写图片描述
–with-ssl有个默认的寻找ssl路径 。

方案二:

先编译安装openssl库,然后再编译curl库。
编译openssl库,

第一步:

--cross-compile-prefix=/usr/local/mips/tool_chain/bin/mipsel-linux-uclibc- --prefix=/usr/local/ssl no-asm shared
  • 1

–cross-compile-prefix为交叉编译工具链,–prefix为指定的安装目录。注意指定的目录为/usr/local/ssl,同上面curl库的–with-ssl参数default路径,no-asm为在交叉编译过程中不使用汇编代码加速编译过程,shared生成动态链接库

第二步:

然后修改Makefile

PLATFORM=mips
CONFIGURE_ARGS=mips
  • 1
  • 2
  • 3

-m64相关的去掉(x86机器会有)

第三步:

make
make install

安装完成后,我们去libcurl库完成交叉编译。

./configure --with-ssl=/usr/local/ssl --host=mipsel-linux CC=/usr/local/mips/tool_chain/bin/mipsel-linux-uclibc-gcc
  • 1

make时可能会有以下错误:
checking for “/dev/urandom”… configure: error: cannot check for file existence when cross compiling

交叉编译时加上以下参数即可。

--with-random=/dev/urandom
  • 1

最后完整的交叉编译libcurl库命令为:

./configure --with-ssl=/usr/local/ssl --host=mipsel-linux CC=/usr/local/mips/tool_chain/bin/mipsel-linux-uclibc-gcc --with-random=/dev/urandom
  • 1

最终结果如下:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/soralaro/article/details/82222017
今日推荐