Ubuntu系统下交叉编译openssl

一、参考资料

OpenSSL&&libcurl库的交叉编译 - hesetone - 博客园

二、准备工作

1. 编译环境

  • 宿主机:Ubuntu 20.04.6 LTS
  • Host:ARM32位
  • 交叉编译器:arm-linux-gnueabihf-gcc-11.1.0

2. 设置交叉编译工具链

在交叉编译之前,需要设置交叉编译工具链的环境变量。

bash 复制代码
export PATH=/path/to/toolchains/arm-linux-gnueabihf/bin:$PATH

三、交叉编译 openssl

1. 下载源码

GitHub - openssl/openssl: TLS/SSL and crypto library

bash 复制代码
tar -xvzf openssl-openssl-3.5.0.tar.gz

2. 生成configure配置

bash 复制代码
setarch i386 ./config no-asm enable-shared --prefix=/path/to/openssl-openssl-3.5.0/arm32_install --cross-compile-prefix=arm-linux-gnueabihf- -v

解释说明

  • setarch i386:声明生成的是32位CPU,如果是64位CPU则去除该部分。
  • enable-shared:生成动态连接库。
  • no-asm: 在交叉编译过程中不使用汇编代码,以加速编译过程,且arm不支持汇编代码。

输出示例:

bash 复制代码
yoyo@yoyo:~/360Downloads/openssl-openssl-3.5.0$ setarch i386 ./config no-asm enable-shared --prefix=/path/to/openssl-openssl-3.5.0/arm32_install --cross-compile-prefix=arm-linux-gnueabihf- -v
C compiler: gcc
C compiler vendor: gnu
C compiler version: 1101
Configuring OpenSSL version 3.5.0 for target linux-x86
Using os-specific seed configuration
Created configdata.pm
Running configdata.pm
Created Makefile.in
Created Makefile
Created include/openssl/configuration.h

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL.md file first)      ***
***                                                                ***
**********************************************************************

3. 修改Makefile

makefile 复制代码
PLATFORM=arm
CROSS_COMPILE=arm-linux-gnueabihf-

# 如果编译出错,则去掉 `-m32`
CNF_CFLAGS=-pthread # -m32
CNF_CXXFLAGS=-std=c++11 -pthread # -m32

注意:如果 Makefile 中存在 -m32-m64,则删除。

4. 编译安装

bash 复制代码
make -j8
make install

编译安装之后的文件目录:

bash 复制代码
yoyo@yoyo:~/360Downloads/openssl-openssl-3.5.0$ tree -L 2 arm32_install/
arm32_install/
├── bin
│   ├── c_rehash
│   └── openssl
├── include
│   └── openssl
├── lib
│   ├── cmake
│   ├── engines-3
│   ├── libcrypto.a
│   ├── libcrypto.so -> libcrypto.so.3
│   ├── libcrypto.so.3
│   ├── libssl.a
│   ├── libssl.so -> libssl.so.3
│   ├── libssl.so.3
│   ├── ossl-modules
│   └── pkgconfig
├── share
│   ├── doc
│   └── man
└── ssl
    ├── certs
    ├── ct_log_list.cnf
    ├── ct_log_list.cnf.dist
    ├── misc
    ├── openssl.cnf
    ├── openssl.cnf.dist
    └── private

5. 移植到开发板

bash 复制代码
# 拷贝 include
cp -r ./arm32_install/include/ /usr/local/openssl/

# 拷贝lib
cp -r ./arm32_install/lib/ /usr/local/openssl/

# 拷贝bin
cp -arf ./arm32_install/bin/ /usr/local/openssl/
相关推荐
Lsetea3 小时前
Nginx HTTPS证书域名不匹配:用SAN与SNI定位 ERR_CERT_COMMON_NAME_INVALID
nginx·https·ssl证书·openssl·tls
bosins4 天前
Windows IIS 配置本地HTTPS 全流程指南:自签名证书 + 端口绑定 + 避坑详解
powershell·openssl
Lsetea8 天前
Nginx报SSL_CTX_use_PrivateKey failed:证书与私钥不匹配怎么排查
nginx·https·ssl证书·openssl·私钥
Lsetea10 天前
SSL证书快过期怎么自动检查:用OpenSSL checkend做7天预警与线上证书验收
https·ssl证书·openssl·systemd·证书监控
k4m7v2pz16 天前
交叉编译 Rust 到 aarch64 Linux 掌机:glibc 版本与 sysroot 重建的完整踩坑记录
rust·glibc·交叉编译·aarch64·zigbuild·sysroot
大鹏的NLP博客25 天前
通用 Linux 嵌入式板端 C/C++ ABI 与 Glibc 依赖治理规范
linux·c++·交叉编译
k4m7v2pz1 个月前
Rust 程序在 ReactOS 上“加载即崩“:从崩溃地址 0x6107104d 到 CRT 依赖的深度排查
rust·交叉编译·逆向工程·reactos·pe格式·windows兼容
k4m7v2pz1 个月前
在Arch Linux笔记本上搭建ReactOS 0.4.15虚拟机:从Mac远程开发调试Windows XP风格应用的完整指南
qemu·虚拟机·kvm·交叉编译·mingw-w64·reactos
蜡台1 个月前
本机 局域网 搭建本地 HTTPS 域名完整方案
网络协议·http·https·openssl
qetfw1 个月前
Debian OpenSSL CA 证书配置参考:根证书、服务证书与验证
linux·debian·ssl·openssl