arm交叉编译openssl和curl

环境:Ubuntu14.04.1 64位

已经安装并配置arm-poky-linux交叉编译器

arm板为IMX6的板子

openssl版本:openssl-OpenSSL_1_0_2r.tar.gz(试过使用1.1的版本,不过报错,编译不过)

解压并进入openssl-OpenSSL_1_0_2r,可以先看一下官方的安装说明INSTALL

打开控制台,先执行交叉编译器环境设置

source /opt/fsl-imx-fb/qt5/environment-setup-cortexa9hf-neon-poky-linux-gnueabi

 

然后执行如下命令,测试环境变量是否设置成功,获取交叉编译器arm-poky-linux-gnueabi-gcc的版本号

 

$CC -v

source命令设置的环境只在当前打开的控制台有效。

开始编译openssl

# 进入openssl-OpenSSL_1_0_2r
cd openssl-OpenSSL_1_0_2r
# 配置并生成Makefile
./config no-asm --prefix=~/arm/openssl

直接make会报错

making all in crypto...
make[1]: 正在进入目录 `/home/kun/kWork/compileLibs/openssl-OpenSSL_1_0_2r/crypto'
/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/perl ../util/mkbuildinf.pl "arm-poky-linux-gnueabi-arm-poky-linux-gnueabi-gcc  -march=armv7-a -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-fb/qt5/sysroots/cortexa9hf-neon-poky-linux-gnueabi -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -O3 -Wall" "linux-x86_64" >buildinf.h

arm-poky-linux-gnueabi-arm-poky-linux-gnueabi-gcc  -march=armv7-a -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-fb/qt5/sysroots/cortexa9hf-neon-poky-linux-gnueabi -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -O3 -Wall   -c -o cryptlib.o cryptlib.c
make[1]: arm-poky-linux-gnueabi-arm-poky-linux-gnueabi-gcc:命令未找到
make[1]: *** [cryptlib.o] 错误 127
make[1]:正在离开目录 `/home/kun/kWork/compileLibs/openssl-OpenSSL_1_0_2r/crypto'
make: *** [build_crypto] 错误 1

需要手动修改Makefile文件,将CC= $(CROSS_COMPILE)arm-poky-linux-gnueabi-gcc 修改为 CC= arm-poky-linux-gnueabi-gcc

还要将文件中两处-m64删除,否则报错如下:

arm-poky-linux-gnueabi-gcc: error: unrecognized command line option '-m64'
make[1]: *** [cryptlib.o] 错误 1

#编译并安装
make
make install

完成后就可以在/home/你用户名/arm/openssl中看到生成的头文件和库文件

编译curl

curl版本:curl-7.64.0.tar.gz

解压,官方安装说明在curl-7.64.0/docs/INSTALL.md

# 配置并生成Makefile
./configure --host=arm-none-linux --prefix=~/arm/curl --with-ssl=~/arm/openssl
# 编译
make
# 安装
make install

到此就安装完成了

在开始的时候直接使用命令source /opt/fsl-imx-fb/qt5/environment-setup-cortexa9hf-neon-poky-linux-gnueabi配置好交叉编译器环境,可以看一下environment-setup-cortexa9hf-neon-poky-linux-gnueabi这个文件,然后可以参考并修改这个文件内容手动配置其他交叉编译器环境

export SDKTARGETSYSROOT=/opt/fsl-imx-fb/qt5/sysroots/cortexa9hf-neon-poky-linux-gnueabi
export PATH=/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/sbin:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/bin:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/sbin:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/../x86_64-pokysdk-linux/bin:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-uclibc:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-musl:$PATH
export CCACHE_PATH=/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/../x86_64-pokysdk-linux/bin:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-uclibc:/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-musl:$CCACHE_PATH
export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT
export PKG_CONFIG_PATH=$SDKTARGETSYSROOT/usr/lib/pkgconfig
export CONFIG_SITE=/opt/fsl-imx-fb/qt5/site-config-cortexa9hf-neon-poky-linux-gnueabi
export OECORE_NATIVE_SYSROOT="/opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux"
export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"
export OECORE_ACLOCAL_OPTS="-I /opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/share/aclocal"
unset command_not_found_handle
export CC="arm-poky-linux-gnueabi-gcc  -march=armv7-a -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CXX="arm-poky-linux-gnueabi-g++  -march=armv7-a -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export CPP="arm-poky-linux-gnueabi-gcc -E  -march=armv7-a -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=$SDKTARGETSYSROOT"
export AS="arm-poky-linux-gnueabi-as "
export LD="arm-poky-linux-gnueabi-ld  --sysroot=$SDKTARGETSYSROOT"
export GDB=arm-poky-linux-gnueabi-gdb
export STRIP=arm-poky-linux-gnueabi-strip
export RANLIB=arm-poky-linux-gnueabi-ranlib
export OBJCOPY=arm-poky-linux-gnueabi-objcopy
export OBJDUMP=arm-poky-linux-gnueabi-objdump
export AR=arm-poky-linux-gnueabi-ar
export NM=arm-poky-linux-gnueabi-nm
export M4=m4
export TARGET_PREFIX=arm-poky-linux-gnueabi-
export CONFIGURE_FLAGS="--target=arm-poky-linux-gnueabi --host=arm-poky-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"
export CFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/home2/zhengsh/linux/yocto/build/tmp/work/x86_64-nativesdk-pokysdk-linux/meta-environment-imx6qsabresd/1.0-r8=/usr/src/debug/meta-environment-imx6qsabresd/1.0-r8 -fdebug-prefix-map=/home2/zhengsh/linux/yocto/build/tmp/sysroots/x86_64-linux= -fdebug-prefix-map=/home2/zhengsh/linux/yocto/build/tmp/sysroots/x86_64-nativesdk-pokysdk-linux= "
export CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types -fdebug-prefix-map=/home2/zhengsh/linux/yocto/build/tmp/work/x86_64-nativesdk-pokysdk-linux/meta-environment-imx6qsabresd/1.0-r8=/usr/src/debug/meta-environment-imx6qsabresd/1.0-r8 -fdebug-prefix-map=/home2/zhengsh/linux/yocto/build/tmp/sysroots/x86_64-linux= -fdebug-prefix-map=/home2/zhengsh/linux/yocto/build/tmp/sysroots/x86_64-nativesdk-pokysdk-linux= "
export LDFLAGS="-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed"
export CPPFLAGS=""
export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"
export OECORE_DISTRO_VERSION="4.1.15-2.0.0"
export OECORE_SDK_VERSION="4.1.15-2.0.0"
export ARCH=arm
export CROSS_COMPILE=arm-poky-linux-gnueabi-

# Append environment subscripts
if [ -d "$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do
	    . $envfile
    done
fi
if [ -d "$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do
	    . $envfile
    done
fi

 

在curl的安装说明中对交叉编译有如下,对比两个文件,可以对其他交叉编译器进行类似的设置

# Cross compile

Download and unpack the curl package.

'cd' to the new directory. (e.g. `cd curl-7.12.3`)

Set environment variables to point to the cross-compile toolchain and call
configure with any options you need.  Be sure and specify the `--host` and
`--build` parameters at configuration time.  The following script is an
example of cross-compiling for the IBM 405GP PowerPC processor using the
toolchain from MonteVista for Hardhat Linux.

    #! /bin/sh

    export PATH=$PATH:/opt/hardhat/devkit/ppc/405/bin
    export CPPFLAGS="-I/opt/hardhat/devkit/ppc/405/target/usr/include"
    export AR=ppc_405-ar
    export AS=ppc_405-as
    export LD=ppc_405-ld
    export RANLIB=ppc_405-ranlib
    export CC=ppc_405-gcc
    export NM=ppc_405-nm

    ./configure --target=powerpc-hardhat-linux
        --host=powerpc-hardhat-linux
        --build=i586-pc-linux-gnu
        --prefix=/opt/hardhat/devkit/ppc/405/target/usr/local
        --exec-prefix=/usr/local

编译的时候参考了如下几篇博客:

https://blog.csdn.net/king_jie0210/article/details/82897759

https://blog.csdn.net/andylauren/article/details/78821916

https://blog.csdn.net/miaodichiyou/article/details/51451134

你可能感兴趣的:(arm交叉编译openssl和curl)