64位ubuntu 12.04系统编译busybox遇到的问题处理办法
今天研究了一下busybox的編譯。自己下了一個busybox-1.25.0的版本(直接從busybox官網上下載:https://busybox.net/downloads/),進行編譯,遇到了一些問題,通過百度搜索和自己摸索,也成功解決了,詳細記錄如下:
首先交代一下系統版本和開發環境:
- 操作系統:ubuntu 12.04(64bit)
- 交叉編譯工具鏈:arm-linux-gcc 4.4.3
- busybox源碼包:busybox-1.25.0
一、修改Makefile配置
首先解壓源碼包:
tar -jxvf busybox-1.25.0.tar.bz2進入busybox-1.25.0目錄,修改Makefile文件如下:
ARCH ?= arm CROSS_COMPILE ?= arm-linux-二、修改配置文件
make menuconfig選擇Busybox Settings—>Build Options—>,選擇[*] Build Busybox as a static binary(no shared libs);
三、編譯源碼,解決問題
make clean 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 miscutils/nandwrite.c:151: error: for each function it appears in.) scripts/Makefile.build:197: recipe for target 'miscutils/nandwrite.o' failed make[1]: *** [miscutils/nandwrite.o] Error 1 Makefile:742: recipe for target 'miscutils' failed make: *** [miscutils] Error 2解決辦法:
MTD_FILE_MODE_RAW在/usr/include/mtd/mtd-abi.h中定義,于是將/usr/include/mtd/mtd-abi.h拷貝到busybox的include文件中,然后在nandwrite.c文件中包含該頭文件:
gedit miscutils/nandwrite.c修改
#include "libbb.h" #include <mtd/mtd-user.h>為
#include "libbb.h" #include "mtd-abi.h" #include <mtd/mtd-user.h>此問題解決。繼續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.) scripts/Makefile.build:197: recipe for target 'util-linux/blkdiscard.o' failed make[1]: *** [util-linux/blkdiscard.o] Error 1 Makefile:742: recipe for target 'util-linux' failed make: *** [util-linux] Error 2解決辦法:
BLKSECDISCARD在/usr/include/linux/fs.h中定義,同上理,直接將/usr/include/linux/fs.h拷貝到busybox的include文件中,不過這次還要額外修改一下文件中的部分內容,否則會出現編譯失敗。
1、屏蔽以下4個頭文件(否則編譯時會提示找不到頭文件):
//#include <linux/limits.h> //#include <linux/ioctl.h> //#include <linux/blk_types.h> //#include <linux/types.h>2、屏蔽以下幾個結構體(否則編譯時會提示找不到類型定義):
#if 0 struct fstrim_range {__u64 start;__u64 len;__u64 minlen; };/* And dynamically-tunable limits and defaults: */ struct files_stat_struct {unsigned long nr_files; /* read only */unsigned long nr_free_files; /* read only */unsigned long max_files; /* tunable */ };struct inodes_stat_t {int nr_inodes;int nr_unused;int dummy[5]; /* padding for sysctl ABI compatibility */ }; #endif然后修改blkdiscard.c中對fs.h頭文件的包含方式:
gedit util-linux/blkdiscard.c修改
#include <linux/fs.h>為
#include "fs.h"繼續make,編譯能通過了。但是在鏈接的時候出現問題:
networking/lib.a(nslookup.o): In function `print_host': nslookup.c:(.text.print_host+0x44): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking debianutils/lib.a(mktemp.o): In function `mktemp_main': mktemp.c:(.text.mktemp_main+0x98): warning: the use of `mktemp' is dangerous, better use `mkstemp' networking/lib.a(ipcalc.o): In function `ipcalc_main': ipcalc.c:(.text.ipcalc_main+0x25c): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking libbb/lib.a(inet_common.o): In function `INET_resolve': inet_common.c:(.text.INET_resolve+0x60): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking networking/lib.a(inetd.o): In function `reread_config_file': inetd.c:(.text.reread_config_file+0x230): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking networking/lib.a(netstat.o): In function `ip_port_str': 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 menuconfigLinux System Utilities—>nsenter,去掉該選項,重新編譯make,又出現如下錯誤:
networking/lib.a(nslookup.o): In function `print_host': nslookup.c:(.text.print_host+0x44): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking debianutils/lib.a(mktemp.o): In function `mktemp_main': mktemp.c:(.text.mktemp_main+0x98): warning: the use of `mktemp' is dangerous, better use `mkstemp' networking/lib.a(ipcalc.o): In function `ipcalc_main': ipcalc.c:(.text.ipcalc_main+0x25c): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking libbb/lib.a(inet_common.o): In function `INET_resolve': inet_common.c:(.text.INET_resolve+0x60): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking networking/lib.a(inetd.o): In function `reread_config_file': inetd.c:(.text.reread_config_file+0x230): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking networking/lib.a(netstat.o): In function `ip_port_str': 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 menuconfigCoreutils—>sync選項去掉,重新make編譯通過,終于順利生成了busybox可執行文件。
OK,今天到此為止,明天再繼續研究。
搞定,收工!
篇后語:
1、編譯完后對上述幾個問題進行反思,發現這幾個問題其實來講可以分為2類。一類是頭文件包含的問題,一類是make menuconfig配置的問題。后者,可能跟每個人的配置需求有關。但是前者的問題,我認為busybox公司完全可以將那2個頭文件直接包含在源碼包中,將相關代碼修改成OK的狀態,讓我們下載過來就可以直接編譯通過,免去我們這番折騰。但是為何busybox公司沒有這么做呢?其中應該是有原因的,暫時想不通,待日后再仔細琢磨吧。
2、本文撰寫時,使用的busybox工具源碼版本是busybox-1.25.0,使用上述方法驗證通過。不過,緊接著,我又驗證了最新的busybox-1.26.2版本,同樣使用上述方法,順利通過,編譯成功。證明本文中的方法應該對于各個版本都是通用的。
3、本文只是簡單的介紹了一下使用busybox過程中遇到幾個編譯出錯的問題的解決辦法,并未對整套編譯流程進行詳細介紹。關于如何利用busybox工具編譯出linux根文件系統的完整流程,可參見我的另外一篇博客(如何使用busybox編譯和生成最簡linux根文件系統(rootfs))。
總結
以上是生活随笔為你收集整理的64位ubuntu 12.04系统编译busybox遇到的问题处理办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我的世界地狱疣在哪(汉典我字的基本解释)
- 下一篇: 如何使用busybox编译和生成最简li