分类: LINUX
2017-05-09 11:54:38
一、修改Makefile配置
首先解压源码包:
tar -jxvf busybox-1.25.0.tar.bz2
进入busybox-1.25.0目录,修改Makefile文件如下:
ARCH ?= $(SUBARCH)
ARCH = arm
CROSS_COMPILE =arm-none-linux-gnueabi-
二、修改配置文件
make menuconfig
选择Busybox Settings--->Build Options--->,选择[*] Build Busybox as a static binary(no shared libs)
三、编译
make
出现如下错误:
miscutils/nandwrite.c: In function 'nandwrite_main':
miscutils/nandwrite.c:151: error: 'MTD_FILE_MODE_RAW' undeclared (first use in this function)
miscutils/nandwrite.c:151: error: (Each undeclared identifier is reported only once
解决在主机/usr目录下
root@ubuntu:/usr# grep "MTD_FILE_MODE_RAW" * -R
知道后数值为3 直接在出错文件中#define MTD_FILE_MODE_RAW 3
继续make,出现如下错误:
util-linux/blkdiscard.c: In function 'blkdiscard_main':
util-linux/blkdiscard.c:72: error: 'BLKSECDISCARD' undeclared (first use in this function)
util-linux/blkdiscard.c:72: error: (Each undeclared identifier is reported only once
util-linux/blkdiscard.c:72: error: for each function it appears in.)
解决办法
在/usr目录
root@ubuntu:/usr# grep "BLKSECDISCARD" * -R
在util-linux/blkdiscard.c中添加
#define BLKSECDISCARD _IO(0x12,125)
或者
BLKSECDISCARD在/usr/include/linux/fs.h中定义,方法如上所述,将/usr/include/linux/fs.h拷贝到busybox的include文件中,然后修改blkdiscard.c中头文件包含:
修改:#include 为#include "fs.h"
继续make,编译通过,但是在链接的时候出现问题:
netstat.c:(.text.ip_port_str+0x50): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
util-linux/lib.a(nsenter.o): In function `nsenter_main':
nsenter.c:(.text.nsenter_main+0x1b0): undefined reference to `setns'
collect2: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
Makefile:717: recipe for target 'busybox_unstripped' failed
make: *** [busybox_unstripped] Error 1
解决办法:
make menuconfig
Linux System Utilities--->nsenter,去掉该选项,重新编译make,又出现如下错误:
netstat.c:(.text.ip_port_str+0x50): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
coreutils/lib.a(sync.o): In function `sync_main':
sync.c:(.text.sync_main+0x7c): undefined reference to `syncfs'
collect2: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
Makefile:717: recipe for target 'busybox_unstripped' failed
make: *** [busybox_unstripped] Error 1
解决办法:
make menuconfig
Coreutils--->sync选项去掉,重新make编译通过,生成了busybox可执行文件。