1、在官网https://busybox.net下载最新源码1.26.2;
2、先导入环境变量:
. /opt/fsl-imx-fb/4.1.15-1.2.0/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi
3、cd到busybox的源码文件夹busybox-1.26.2,配置编译选项$make menuconfig:
Busybox Settings --->Cross Compiler prefix(回车),填入arm-poky-linux-gnueabi-
退出保存,$make,会有找不到头文件的报错:
In file included from /opt/fsl-imx-fb/4.1.15-1.2.0/sysroots/i686-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.2.0/include-fixed/syslimits.h:7:0,
from /opt/fsl-imx-fb/4.1.15-1.2.0/sysroots/i686-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.2.0/include-fixed/limits.h:34,
from include/platform.h:141,
from include/libbb.h:13,
from include/busybox.h:8,
from applets/applets.c:9:
/opt/fsl-imx-fb/4.1.15-1.2.0/sysroots/i686-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.2.0/include-fixed/limits.h:168:61:error: no include path in which to search for limits.h
In file included from include/libbb.h:13:0,
from include/busybox.h:8,
from applets/applets.c:9:
include/platform.h:152:23: fatal error: byteswap.h: No such file or directory
compilation terminated.
make[1]: *** [applets/applets.o] Error 1
make: *** [applets_dir] Error 2
可以看到提示说找不到一些标准的头文件,其实这个是因为我们没有添加一些指定的选择来告诉其使用byteswap.h,所以默认的去查找byteswap.h。
要在make menuconfig中相应的选项中指定路径:
其中最为核心的是sysroot这个选项,这个选项将告诉toolchian去哪里查找库与头文件,而如果不指定这个,那么就会出现问题。
4、$make&&make install后,会生成_install文件夹,其中包含link到busybox的所有工具,替换到rootfs中即可。
*另:
在本地项目中直接用yotco的toolchain编译,将Makefile.Rules的CROSS_COMPILE指定到yocto的toolchain:
CROSS_COMPILE = /opt/fsl-imx-fb/4.1.15-1.2.0/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-
直接make也会报一些找不到标准头文件的错:
fatal error:unistd.h: No such file or directory
compilation terminated.
也是在编译选项中没指定路径的问题,修改如下(红色字体):
CXX = $(CROSS_COMPILE)g++ --sysroot=/opt/fsl-imx-fb/4.1.15-1.2.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi
CC = $(CROSS_COMPILE)gcc --sysroot=/opt/fsl-imx-fb/4.1.15-1.2.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi
LINK = $(CROSS_COMPILE)g++ --sysroot=/opt/fsl-imx-fb/4.1.15-1.2.0/sysroots/cortexa9hf-vfp-neon-poky-linux-gnueabi
参考:
http://blog.csdn.net/sy373466062/article/details/50388222