linux 交叉编译OpenSSL

fslejnso  于 2023-06-21  发布在  Linux
关注(0)|答案(1)|浏览(141)

我在ubuntu x86-64上,试图使用编译选项-g -gdwarf-4 -O3和clang和gcc编译ARM/AARCH 64/i686的OpenSSL,并使用以下命令来这样做,但似乎无法理解我做错了什么。我遵循OpenSSL和BinKit的说明,但我不确定我错过了什么。
以aarch 64为例:

./Configure linux-generic64 shared --cross-compiler-prefix="\aarch64-ubuntu-linux-gnu-\" -g -O2 -gdwarf-4

这导致:“无法识别的命令行:aarch64-ubuntu-linux-gnu
当我尝试将参数传递给./config时,我得到错误:“无法识别的命令行选项:-m64”
我知道问题是我没有输入正确的命令,但我也不知道怎么做!

xuo3flqw

xuo3flqw1#

您应该指定整个前缀。例如,如果要用途:
/opt/arm/9/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc
作为编译器,用途:
--cross-compile-prefix=/opt/arm/9/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-
当指定--cross-compile-prefix选项时。
因此,一个完整的,针对linux aarch64的工作过程的例子是:

# Retrieve openssl.
wget https://www.openssl.org/source/openssl-3.1.1.tar.gz

# Retrieve a toolchain I know is working.
wget "https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz?rev=6750d007ffbf4134b30ea58ea5bf5223&hash=6C7D2A7C9BD409C42077F203DF120385AEEBB3F5" -O arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz

# Install the toolchain.
mkdir -p /opt/arm/12
tar Jxf arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz  -C /opt/arm/12

# Build openssl for linux aarch64.
tar zxf openssl-3.1.1.tar.gz
cd openssl-3.1.1
./Configure linux-aarch64 --cross-compile-prefix=/opt/arm/12/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- --prefix=/opt/openssl-3.1.1 --openssldir=/opt/openssl-3.1.1 -static -g -O2 -gdwarf-4
make install

# Verify executables were built.
ls -gG /opt/openssl-3.1.1/bin/
total 28372
-rwxr-xr-x 1     6884 Jun 15 22:14 c_rehash
-rwxr-xr-x 1 29065376 Jun 15 22:14 openss

# Display information on executable.
file /opt/openssl-3.1.1/bin/openssl
/opt/openssl-3.1.1/bin/openssl: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, with debug_info, not stripped

# Display openssl version using qemu-system-aarch64.
/opt/qemu-8.0.2/bin/qemu-aarch64 /opt/openssl-3.1.1/bin/openssl version
OpenSSL 3.1.1 30 May 2023 (Library: OpenSSL 3.1.1 30 May 2023)

使用相同的过程配置linux-generic64似乎也可以正常工作:

./Configure linux-generic64 --cross-compile-prefix=/opt/arm/12/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu- --prefix=/opt/openssl-3.1.1 --openssldir=/opt/openssl-3.1.1 -static -g -O2 -gdwarf-4
make all

file apps/openssl
./apps/openssl: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, with debug_info, not stripped

相关问题