使用yocto的工具链单独编译C文件

本文转载自CSDN,点击此处访问原文!
1.Restarting a build environment
source setup-environment

2.gcc工具链

bitbake meta-toolchain
./tmp/deploy/sdk/poky-glibc-x86_64-meta-toolchain-cortexa7hf-vfp-neon-toolchain-1.8.sh

3.QT工具链
bitbake meta-toolchain-qt5

4.编译uboot
source /opt/poky/1.8/environment-setup-cortexa7hf-vfp-neon-poky-linux-gnueabi
make mx6ul_14x14_evk_defconfig
make

5.编译kernel
export ARCH=arm
export CROSS_COMPILE=$TARGET_PREFIX
unset LDFLAGS
make imx_v7_defconfig
make uImage LOADADDR=0x10008000

make命令会生成Linux的dtb文件

6.单独编译C文件

yangzhiwen@yzw-kingsee:~$ cd /home/work/Elmo/test/test/
yangzhiwen@yzw-kingsee:/home/work/Elmo/test/test$ ls
main.c  test
yangzhiwen@yzw-kingsee:/home/work/Elmo/test/test$ rm test 
yangzhiwen@yzw-kingsee:/home/work/Elmo/test/test$ cat main.c 
#include "stdlib.h"
#include "stdio.h"

void main(void)
{
        printf("Hello world\n");
}
yangzhiwen@yzw-kingsee:/home/work/Elmo/test/test$ source /opt/poky/1.8/environment-setup-cortexa7hf-vfp-neon-poky-linux-gnueabi 
yangzhiwen@yzw-kingsee:/home/work/Elmo/test/test$ echo $CC
arm-poky-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/opt/poky/1.8/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi
yangzhiwen@yzw-kingsee:/home/work/Elmo/test/test$ $CC main.c -o test
yangzhiwen@yzw-kingsee:/home/work/Elmo/test/test$ file test
test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=ad28e302b106823c7cbcd038f9cb4940c14b5f57, not stripped
yangzhiwen@yzw-kingsee:/home/work/Elmo/test/test$ 

作者:yangzhiwen56
来源:CSDN
原文:https://blog.csdn.net/yangzhiwen56/article/details/50592891
版权声明:本文为博主原创文章,转载请附上博文链接!

如果不设置好环境,交叉编译工具就找不到头文件,下面是我自己的编译环境
marvin@ubuntu:cantool$ source /opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa9hf-neon-poky-linux-gnueabi
marvin@ubuntu:cantool$ export ARCH=arm
marvin@ubuntu:cantool$ export CROSS_COMPILE=arm-poky-linux-gnueabi-
marvin@ubuntu:cantool$ echo $CC
arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa9hf-neon-poky-linux-gnueabi
marvin@ubuntu:cantool$ $CC ./cantool.c -o cantool-arm

你可能感兴趣的:(使用yocto的工具链单独编译C文件)