Linux下交叉编译openssl

2019-07-13 07:01发布


1. 安装交叉编译器,这里用的是gcc-linaro-arm-linux-gnueabihf-4.8,当然也可以使用更高版本 非官方下载地址:http://download.csdn.net/detail/huangchijun11/9828071 官方下载地址:https://www.linaro.org/downloads/ 官方网站上根据你的CPU指令集选择arm-linux-gnueabihf或者armv8l-linux-gnueabihf,这里编译的是32位,因此选择arm-linux-gnueabihf。 另外,官方给出了种gcc版本,但最低版本是4.9-2016.02,系列下载地址:https://releases.linaro.org/components/toolchain/binaries/
解压至/opt/arm-linux-gnueabihf-4.8,修改用户目录下面的.bashrc,追加export PATH=$PATH:/opt/arm-linux-gnueabihf-4.8/bin 然后重新打开shell窗口即可,用arm-linux-gnueabihf-gcc --version检查编译器是否安装成功 2. 获取Git代码库 $mkdir openssl-dir $cd openssl-dir $git clone https://github.com/openssl/openssl.git 3. 切换到最新发布版本,这里使用的是FIPS版本的,当前最新版本是OpenSSL-fips-2_0_9。(通过git tag查看当前版本) $mkdir arm-openssl arm-ssl // 这两个目录用于之后编译openssl $cd openssl $git checkout -b local/OpenSSL-fips-2_0_9 $setarch i386 ./config no-asm no-shared enable-ssl3 enable-ssl3-method enable-tls1_3 --prefix= --openssldir= --cross-compile-prefix=arm-linux-gnueabihf- 说明:具体配置参数请参考openssl代码目录中的INSTALL文档,简单说明以下参数: setarch i386: 指编译32位,如果不指定就会报错,当然如果忘记指定也可以在生成的Makefile文件中删除-m64标志来解决 no-shared: 指静态编译,只生成静态库 --cross-compile-prefix: 指定交叉编译器前缀 $make $make install_sw// Use "make install_sw" to install the software without documentation 4. 在arm-openssl和arm-ssl目录中即生成编译之后的文件。