arm交叉编译jsoncpp

系统:Ubuntu 14.04 64位

cmake版本:cmake version 3.14.0-rc4

目标:arm板

交叉编译器:arm-poky-linux-gnueabi-gcc   5.3.0

jsoncpp下载地址:https://github.com/open-source-parsers/jsoncpp/releases

使用版本:jsoncpp-1.8.4.tar.gz

参考cmake官方说明和其他人经验

https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-toolchain

https://www.cnblogs.com/rickyk/p/3875334.html

先创建一个用于cmake的交叉编译器的配置文件,我是在主目录下创建的一个文件crossCompilingSetting,文件内容如下:

 


#Cross Compiling for Linux

# configure target system info
SET(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

#sysroot,It can also be set in the compile flag
#For example set(CMAKE_CXX_FLAGS "--sysroot=/opt/fsl-imx-fb/qt5/sysroots/cortexa9hf-neon-poky-linux-gnueabi ${CMAKE_CXX_FLAGS}")
set(CMAKE_SYSROOT /opt/fsl-imx-fb/qt5/sysroots/cortexa9hf-neon-poky-linux-gnueabi)

#The CMAKE_STAGING_PREFIX is also optional. It may be used to specify a path on the host to install to. The CMAKE_INSTALL_PREFIX is always the runtime installation location, even when cross-compiling.
#set(CMAKE_STAGING_PREFIX /home/devel/stage)

# specify the cross compiler
SET(CMAKE_C_COMPILER /opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER /opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++)
# set compiler flags
set(CMAKE_C_FLAGS "-march=armv7-a -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9 ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a9 ${CMAKE_CXX_FLAGS}")

# where is the target environment 
#SET(CMAKE_FIND_ROOT_PATH  /opt/fsl-imx-fb/qt5/sysroots/cortexa9hf-neon-poky-linux-gnueabi)

#CMake find_* commands will look in the sysroot, and the CMAKE_FIND_ROOT_PATH entries by default in all cases, as well as looking in the host system root prefix.
# search for programs in the build host directories (not necessary)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)


# configure Qt
#SET(QT_QMAKE_EXECUTABLE /opt/fsl-imx-fb/qt5/sysroots/x86_64-pokysdk-linux/usr/bin/qt5/qmake)

# configure Boost
#SET(BOOST_ROOT /opt/boost_arm)

然后解压jsoncpp-1.8.4.tar.gz并修改CMakeLists.txt文件

option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)

改为

option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" OFF)

不编译测试工程,因为测试工程会编译失败,当然库文件还是会生成的,所以不修改也行

开始编译

cd jsoncpp-1.8.4/
# 创建一个build目录,方便编译后清理
mkdir build
cd build/
# 生成Makefile
cmake -DCMAKE_TOOLCHAIN_FILE=~/crossCompilingSetting -DCMAKE_INSTALL_PREFIX=~/arm/jsoncpp ..
# 编译,并安装
make
make install

至此就编译并安装完成

除了创建cmake的交叉编译器的配置文件外,还有种方法可以用,配置编译环境变量,就像我使用的交叉编译器,可以直接

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

配置完所需要的变量,然后不用做其他处理就可以直接 cmake  -DCMAKE_INSTALL_PREFIX=~/arm/jsoncpp ..

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值