openssl交叉编译
下载
到https://www.openssl.org/source/下载最新openssl源代码。
或使用git直接下拉代码,并切换到最新release版.
此处我下载的是1.1.1系列的版本,这个版本支持到2023年9月11号
git clone https://gitee.com/mirrors/openssl.git
#找到最新版的release tag
git checkout -b openssl-1.1.1m OpenSSL_1_1_1m
解压
tar -zxvf openssl-1.1.1m.tar.gz
适配T40
创建make.sh
在根目录
#!/bin/sh
CONFIG_OUTPUT=$(pwd)/install
CROSS_TOOL_PREFIX=~/work/t40/mips-gcc720-glibc226/bin/mips-linux-uclibc-gnu-
CFLAGS1=-muclibc
CFLAGS2=-march=mips32r2
./config no-asm no-async shared $CFLAGS1 $CFLAGS2 --prefix=$CONFIG_OUTPUT --cross-compile-prefix=$CROSS_TOOL_PREFIX
make clean
make
make install
make distclean
config脚本参数说明:
- no-asm: 在交叉编译过程中不使用汇编代码代码加速编译过程.
- shared: 生成动态连接库。
- no-async: 交叉编译工具链没有提供GNU C的ucontext库时,就需要加上
- –prefix=: 安装路径,编译完成install后将有bin,lib,include等文件夹
- –cross-compile-prefix=: 交叉编译工具
同时也可以在INSTALL.md
文档中可以看到相关解释
no-asm
Do not use assembler code. This should be viewed as
debugging/trouble-shooting option rather than production.
On some platforms a small amount of assembler code may
still be used even with this option.
no-async
Do not build support for async operations.
no-shared
Do not create shared libraries, only static ones. See "Note
on shared libraries" below.
常见问题
问题1
在T40平台,使用curl库封装的http client时,出现错误。
错误现象
* Trying 47.115.62.228:443...
* Connected to test.apicn.xmitech.net (47.115.62.228) port 443 (#0)
* ALPN, offering http/1.1
* error:0306E06C:bignum routines:BN_mod_inverse:no inverse
* Closing connection 0
curl_easy_perform() failed: SSL connect error
错误原因
经过一番查找,定位于通过config
文件生成的Makefile
中的PLATFORM
值有问题了。由于编译选项中没有指定芯片架构,配置脚本在猜测时将芯片架构猜测为linux-x86_64。
#有问题的makefile
PLATFORM=linux-x86_64
解决方法
- 将
openssl
源代码的config
文件拉到T40环境下运行
[root@Zeratul:sd]# ./config -h
Usage: config [options]
-d Build with debugging when possible.
-t Test mode, do not run the Configure perl script.
-v Verbose mode, show the exact Configure call that is being made.
-h This help.
Any other text will be passed to the Configure perl script.
See INSTALL for instructions.
Operating system: mips-whatever-linux2
You need Perl 5.
- 然后将得到的
Operating system:
值放在config
中修改
# read the output of the embedded GuessOS
read GUESSOS
GUESSOS="mips-whatever-linux2"
echo Operating system: $GUESSOS
- 修完毕后,执行
make.sh
脚本即可。
问题2
错误现象
./libcrypto.so: warning: gethostbyname is obsolescent, use getnameinfo() instead.
./libcrypto.so: undefined reference to `getcontext'
./libcrypto.so: undefined reference to `setcontext'
./libcrypto.so: undefined reference to `makecontext'
错误原因
交叉编译工具链没有提供GNU C的ucontext库。
解决方法
在运行config脚本时添加 no-async选项。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)