Linux 交叉编译(toolchain) ARM 版 libssl.so.1.1 libcrypto.so.1.1 库

前言全局说明


一、说明

环境:

CentOS 7

二、下载源码:

官网:
https://www.openssl.org/

历史版本,源码下载:
https://openssl-library.org/source/old/index.html

下载,指定版本:

wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz

三、依赖环境

3.1


四、编译

4.1 生效编译环境

#!/bin/bash

export QL_SDK_TARGET_SYSROOT="/root/ql-ol-crosstool/ql-sysroots"

######legacy env variables. please not use them######
export SDKTARGETSYSROOT=${QL_SDK_TARGET_SYSROOT}
export PATH=$PATH:/root/ql-ol-crosstool/bin
export STAGING_DIR=/root/ql-ol-crosstool/ql-sysroots
echo -e "\033[33;1mQUECTEL_PROJECT_NAME      =AG35\033[0m"
echo -e "\033[33;1mQUECTEL_PROJECT_REV       =AG35-1806E\033[0m"

export CC="arm-openwrt-linux-gcc -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard"
export CXX="arm-openwrt-linux-g++ -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard"
export CPP="arm-openwrt-linux-gcc -E -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard"
export AS="arm-openwrt-linux-as "
export LD="arm-openwrt-linux-ld "
export GDB=arm-openwrt-linux-gdb
export STRIP=arm-openwrt-linux-strip
export RANLIB=arm-openwrt-linux-ranlib
export OBJCOPY=arm-openwrt-linux-objcopy
export OBJDUMP=arm-openwrt-linux-objdump
export AR=arm-openwrt-linux-ar
export NM=arm-openwrt-linux-nm
export M4=m4
export CETLIB=/root/ql-ol-crosstool/ql-ag35-1806e-gcc-8.4.0-glibc-v1-toolchain
export TARGET_PREFIX=arm-openwrt-linux-
export CFLAGS=" -O2 --sysroot=$STAGING_DIR -Wa,--noexecstack -fexpensive-optimizations -frename-registers -fomit-frame-pointer -ftree-vectorize   -finline-functions -finline-limit=64   -Wno-error=maybe-uninitialized -Wno-error=unused-result -I$CETLIB/include"
export CXXFLAGS=" -O2 --sysroot=$STAGING_DIR -Wa,--noexecstack -fexpensive-optimizations -frename-registers -fomit-frame-pointer -ftree-vectorize   -finline-functions -finline-limit=64   -Wno-error=maybe-uninitialized -Wno-error=unused-result -I$CETLIB/include"
export LDFLAGS=" -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -L$CETLIB/lib -L$:q/usr/lib"
export CPPFLAGS=""
export ARCH=arm

4.2 编译

4.2.1 生成 Makefile
./config no-asm shared --cross-compile-prefix=/root/ql-ol-crosstool/bin/arm-openwrt-linux- 

no-asm:不使用汇编程序加速编译过程,因为汇编程序对arm格式不支持。
shared:即生成静态库也生成动态库,no-share不生成动态库,仅有静态库
--cross-compile-prefix=:指定交叉工具链,添加指定的前缀到binutils组件。若为相对路径,需配置对应的环境变量。


4.2.2 修改 Makefile
1. PLATFOR(PLATFORM) 变量 linux-x86_64 修改为 arm
2.删除-m64编译选项       (vim可通过/-m64进行查找)

4.3 源码编译

4.3.1 全速编译,使用CPU全部核心
make -j $(nproc)
4.3.2 -j4 用4个线程编译
make -j4
4.3.2 单线程编译,慢
make

编译时间测试:
同样 openssl-1.1.1g 源码,
16线程编译: 约 25 秒
单线程编译: 约 180 秒(3分钟)


4.4 安装

不需要执行 make install ,因为so是放到嵌入设备的,不是放到当前编译环境的。


4.5 编译结果

cd openssl-1.1.1g/
ll libssl.so.1.1 libcrypto.so.1.1

执行成功部分截图
image


4.6 查看文件架构

file libssl.so.1.1
file libcrypto.so.1.1

image
image



免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。




参考、来源:
https://chat.baidu.com/search?isShowHello=1&replace=1&extParams={"ori_lid"%3A"9243225738834660326"%2C"enter_type"%3A""%2C"subEnterType"%3A"his_middle"%2C"forceRefresh"%3A1761205688990} (源码下载)
https://developer.aliyun.com/article/1135168 (源码下载)
https://blog.csdn.net/weixin_42645653/article/details/121429584
https://www.cnblogs.com/wutou/p/18757139
https://blog.csdn.net/weixin_46639310/article/details/132587940 (有详细截图)



posted @ 2025-10-24 09:57  悟透  阅读(13)  评论(0)    收藏  举报