在linux开发中,设置到安全认证或者数据加密时,往往设计到使用openssl。但是在有些嵌入式的环境下,系统一般不会带该库或者自带的库版本不满足开发要求,所以往往我们需要自己编译库文件,下面记录下在自己在编译过程中的步骤及遇到的问题,供日后参考使用。
1、openssl库的源码下载
官网下载地址: http://distfiles.macports.org/openssl/ 进去后选择自己需要的版本,右键复制地址后,使用下面的命令下载
例如: wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2k.tar.gz
2、ubuntu下编译安装openssl
a. ./config配置生成Makefile,-shared 表示生成动态库,也可通过参数 -prefix=xxx 自行指定安装目录,如下不配置则为默认安装路径(/usr/local/ssl/lib)
b. make
c. make install
d. 在以上的步骤中,可能遇到"perl: warning: Please check that your locale settings" 的问题,解决如下:
在终端执行:
export LC_ALL=C (参考:https://www.cnblogs.com/chenqionghe/p/11478269.html)
e. LC_ALL=C 的含义:
参考: https://www.cnblogs.com/wajika/p/6592659.html
3、openssl 交叉编译
方式一:
a. 交叉编译与Ubuntu编译类似,配置时通过【--prefix=绝对路径】选项指定安装路径(自行创建文件夹),然后修改Makefile文件,修改方式如下:
b. 指定交叉编译工具链
1. 修改CC
2.删掉Makefile中的-m64 搜索-m64选项并删除,共两处
3. make
4. make install
参考: https://blog.csdn.net/fangye945a/article/details/86658621
方式二:
不用修改Makefile的方式交叉编译openssl,
1. 配置
./config no-asm shared --prefix=/home/huyh/curl/openssl/build_arm CROSS_COMPILE=/opt/EC20/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi- CC=gcc
2. make
3. 参考文档 https://www.cnblogs.com/djw316/p/10786173.html
以上是个人学习中总结的过程,在期间参考了一些文档,在此表示感谢!