1、到openssl官网下载最新的源码,当前最新版本openssl-1.1.1d.tar.gz,拷贝到虚拟机里
2、将openssl-1.1.1d.tar.gz拷贝到要操作的路径(必须在虚拟机非共享文件夹下),本次测试在/home路径下进行解压
(1)$ cd /home
(2)$ tar -zxvf openssl-1.1.1d.tar.gz
得到openssl-1.1.1d文件夹
3、进入openssl-1.1.1d文件夹,执行./config no-asm shared no-async --prefix=$(pwd)/install --cross-compile-prefix=arm-none-linux-gnueabi- 生成Makefile文件
no-asm 在交叉编译过程中不使用汇编代码代码加速编译过程.原因是它的汇编代码是对arm格式不支持的。
shared 生成动态链接库
no-async 交叉编译工具链没有提供GNU C的ucontext库
--prefix= 指定安装路径
--cross-compile-prefix= 指定交叉编译器
4、vim Makefile 把带-m64 -m32选项去掉
5、make && make install ,成功生成install目录,里面有include和lib文件夹,lib文件夹内有生成的库文件libssl.so.1.1 、libcrypto.so
6、用交叉编译器编译源码文件https_client.c
arm-none-linux-gnueabi-gcc -I /home/openssl-1.1.1d/install/include/ -L /home/openssl-1.1.1d/install/lib/ -lcrypto -lssl https_client.c -o https_client
7、成功编译得到https_client应用程序,将https_client拷贝到开发板,并且把libssl.so.1.1 、libcrypto.so两个库文件添加到开发板的/lib/里面
8、运行https_client进行测试
移植过程遇到的问题:
(1)在编译时,因为没有添加-I /home/openssl-1.1.1d/install/include/ 参数,导致编译时报找不到头文件错误
(2)在编译时,因为添加的-I /home/openssl-1.1.1d/install/include/openssl/ 参数里面多添加了/openssl导致编译时候报找不到头文件错误
(3)在整个工程编译过程,因为有多个Makefile,漏掉了https_client.c所在文件夹的Makefile没有添加-I /home/openssl-1.1.1d/install/include/参数导致报缺少头文件错误
(4)没有添加-L /home/openssl-1.1.1d/install/lib/ -lcrypto -lssl 指定动态链接库路径导致编译不通过
注意:指定动态链接库时,库文件名为libcrypto.so,则写成-lcrypto 将前面的lib改成l,后面的.so去掉