在使用之前需要先source env,导入各种环境变量(注意将路径变更成你自己的):
source ../qt5_sdk/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
然后我们可以查看一下bash的env了,下面是多出来的一些env,直接在bash中输入export即可看到:
declare -x AR="arm-poky-linux-gnueabi-ar" declare -x ARCH="arm" declare -x AS="arm-poky-linux-gnueabi-as " declare -x CC="arm-poky-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/media/work/iMX6/Yocto/qt5_sdk/sysroots /cortexa9hf-vfp-neon-poky-linux-gnueabi" declare -x CFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types" declare -x CONFIGURE_FLAGS="--target=arm-poky-linux-gnueabi --host=arm-poky-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=/media/work/iMX6/Yocto/qt5_sdk/sysro ots/cortexa9hf-vfp-neon-poky-linux-gnueabi" declare -x CONFIG_SITE="/media/work/iMX6/Yocto/qt5_sdk/site-config-cortexa9hf-vfp-neon-poky-linux-gnueabi" declare -x CPP="arm-poky-linux-gnueabi-gcc -E -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/media/work/iMX6/Yocto/qt5_sdk/sysr oots/cortexa9hf-vfp-neon-poky-linux-gnueabi" declare -x CPPFLAGS="" declare -x CROSS_COMPILE="arm-poky-linux-gnueabi-" declare -x CXX="arm-poky-linux-gnueabi-g++ -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/media/work/iMX6/Yocto/qt5_sdk/sysroot s/cortexa9hf-vfp-neon-poky-linux-gnueabi" declare -x CXXFLAGS=" -O2 -pipe -g -feliminate-unused-debug-types" declare -x M4="m4" declare -x MANDATORY_PATH="/usr/share/gconf/kde-plasma.mandatory.path" declare -x NM="arm-poky-linux-gnueabi-nm" declare -x OBJCOPY="arm-poky-linux-gnueabi-objcopy" declare -x OBJDUMP="arm-poky-linux-gnueabi-objdump" declare -x OECORE_ACLOCAL_OPTS="-I /media/work/iMX6/Yocto/qt5_sdk/sysroots/x86_64-pokysdk-linux/usr/share/aclocal" declare -x OECORE_DISTRO_VERSION="1.7" declare -x OECORE_NATIVE_SYSROOT="/media/work/iMX6/Yocto/qt5_sdk/sysroots/x86_64-pokysdk-linux" declare -x OECORE_SDK_VERSION="1.7" declare -x OECORE_TARGET_SYSROOT="/media/work/iMX6/Yocto/qt5_sdk/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi" declare -x OLDPWD="/media/work/iMX6/Yocto/video2lcd_arm/test" declare -x PATH="/media/work/iMX6/Yocto/qt5_sdk/sysroots/x86_64-pokysdk-linux/usr/bin:/media/work/iMX6/Yocto/qt5_sdk/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:/home/hexiongjun/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/hexiongjun/010editor:/home/hexiongjun/010editor" declare -x PKG_CONFIG_PATH="/media/work/iMX6/Yocto/qt5_sdk/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi/usr/lib/pkgconfig" declare -x PKG_CONFIG_SYSROOT_DIR="/media/work/iMX6/Yocto/qt5_sdk/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi" declare -x PWD="/media/work/iMX6/Yocto/video2lcd_arm" declare -x PYTHONHOME="/media/work/iMX6/Yocto/qt5_sdk/sysroots/x86_64-pokysdk-linux/usr" declare -x QMAKESPEC="/home/hexiongjun/github/BBB/SDK/ti-sdk-am335x-evm-05.07.00.00/linux-devkit/arm-arago-linux-gnueabi/usr/share/qtopia/mkspecs/linux-g++" declare -x QT_IM_MODULE="fcitx" declare -x QT_PLUGIN_PATH="/home/hexiongjun/.kde/lib/kde4/plugins/:/usr/lib/kde4/plugins/" declare -x RANLIB="arm-poky-linux-gnueabi-ranlib" declare -x SDKTARGETSYSROOT="/media/work/iMX6/Yocto/qt5_sdk/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi" declare -x SESSION_MANAGER="local/hexiongjun-pc:@/tmp/.ICE-unix/3595,unix/hexiongjun-pc:/tmp/.ICE-unix/3595"
其中我们重点需要关注的是与编译相关的变量:
可以看到CC已经被重定义为cross toolchain了,而ARCH和CROSS_COMPILE也悉心的帮我们配置成了对应的。
因此,其实如果我们需要交叉编译一个app,那么很多变量将不再需要自己手动设定了。
同时因为各种tuning的指定,我们必须注意和硬件的匹配。例如这里指定了为cortex-a9而优化。
最好的方法就是使用变量来使用Toolchian,例如使用$CC而不是使用arm-poky-XXX-gcc,因为我们可以看到CC其实是对arm-xxx-gcc添加了一些配置:
CC="arm-poky-linux-gnueabi-gcc -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/media/work/iMX6/Yocto/qt5_sdk/sysroots /cortexa9hf-vfp-neon-poky-linux-gnueabi"
$ make make -C ./ -f /media/work/iMX6/Yocto/video2lcd_arm/Makefile.build make[1]: Entering directory `/media/work/iMX6/Yocto/video2lcd_arm' make -C convert -f /media/work/iMX6/Yocto/video2lcd_arm/Makefile.build make[2]: Entering directory `/media/work/iMX6/Yocto/video2lcd_arm/convert' arm-poky-linux-gnueabi-gcc -Wall -Werror -O2 -g -I /media/work/iMX6/Yocto/video2lcd_arm/include -I /media/work/iMX6/Yocto/imx6qsabresd_build/tmp/work/imx6qsabresd-poky-linux-gnueabi/fsl-image-qt5/1.0-r0/rootfs/usr/include/ -Wp,-MD,.convert_manager.o.d -c -o convert_manager.o convert_manager.c In file included from /media/work/iMX6/Yocto/imx6qsabresd_build/tmp/work/imx6qsabresd-poky-linux-gnueabi/fsl-image-qt5/1.0-r0/rootfs/usr/include/features.h:389:0, from /media/work/iMX6/Yocto/imx6qsabresd_build/tmp/work/imx6qsabresd-poky-linux-gnueabi/fsl-image-qt5/1.0-r0/rootfs/usr/include/stdio.h:27, from /media/work/iMX6/Yocto/video2lcd_arm/include/config.h:5, from convert_manager.c:2: /media/work/iMX6/Yocto/imx6qsabresd_build/tmp/work/imx6qsabresd-poky-linux-gnueabi/fsl-image-qt5/1.0-r0/rootfs/usr/include/gnu/stubs.h:7:29: fatal error: gnu/stubs-soft.h: No such file or directory # include <gnu/stubs-soft.h> ^ compilation terminated. make[2]: *** [convert_manager.o] Error 1 make[2]: Leaving directory `/media/work/iMX6/Yocto/video2lcd_arm/convert' make[1]: *** [convert] Error 2 make[1]: Leaving directory `/media/work/iMX6/Yocto/video2lcd_arm' make: *** [all] Error 2
例如我们编译一个helloworld,那么可以按照如下编译:
$CC hello.c -o hello