首页 > 代码库 > Yocto tips (19): Yocto SDK Toolchian的使用

Yocto tips (19): Yocto SDK Toolchian的使用

在使用之前须要先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"

注意点

当中我们重点须要关注的是与编译相关的变量:

  1. CC/LD等编译相关
  2. ARCH/CROSS_COMPILE等croos编译相关

能够看到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"

当中最为核心的是sysroot这个选项,这个选项将告诉toolchian去哪里查找库与头文件,而假设不指定这个,那么就会出现故障。比如,我们直接使用arm-poky-gnueabi-gcc来编译:

$ 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

能够看到提示说找不到一些标准的头文件。事实上这个是由于我们没有加入一些指定的选择来告诉其使用stubs-hard.h。所以默认的去查找stubs-soft.h。

比如我们编译一个helloworld,那么能够依照例如以下编译:

$CC hello.c -o hello


这样将省去了诸多选项的手动指定,也不会出问题。



Yocto tips (19): Yocto SDK Toolchian的使用