C语言 交叉编译busybox失败

cwxwcias  于 2023-06-28  发布在  其他
关注(0)|答案(3)|浏览(183)

我正试图为我的嵌入式Linux设备交叉编译忙碌盒V1.27.2.我将共享库构建和交叉编译器前缀以及Sysroot设置为我的编译器目标。编译器在尝试编译大多数库文件后无法链接它们。我收到了这个:

Trying libraries: crypt m
Failed: -Wl,--start-group  -lcrypt -lm  -Wl,--end-group
Output of:
/home/bluebird/brcm-armtools-64bit/tools/le_arm11_external_20090306/bin/arm-brcm-linux-gnueabi-gcc -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -Os -fpic -fvisibility=hidden --sysroot=/home/bluebird/brcm-armtools-64bit/tools/le_arm11_external_20090306/sysroot -o busybox_unstripped -Wl,--sort-common -Wl,--sort-section,alignment -Wl,--gc-sections -Wl,--start-group applets/built-in.o archival/lib.a archival/libarchive/lib.a console-tools/lib.a coreutils/lib.a coreutils/libcoreutils/lib.a debianutils/lib.a e2fsprogs/lib.a editors/lib.a findutils/lib.a init/lib.a libbb/lib.a libpwdgrp/lib.a loginutils/lib.a mailutils/lib.a miscutils/lib.a modutils/lib.a networking/lib.a networking/libiproute/lib.a networking/udhcp/lib.a printutils/lib.a procps/lib.a runit/lib.a selinux/lib.a shell/lib.a sysklogd/lib.a util-linux/lib.a util-linux/volume_id/lib.a archival/built-in.o archival/libarchive/built-in.o console-tools/built-in.o coreutils/built-in.o coreutils/libcoreutils/built-in.o debianutils/built-in.o e2fsprogs/built-in.o editors/built-in.o findutils/built-in.o init/built-in.o libbb/built-in.o libpwdgrp/built-in.o loginutils/built-in.o mailutils/built-in.o miscutils/built-in.o modutils/built-in.o networking/built-in.o networking/libiproute/built-in.o networking/udhcp/built-in.o printutils/built-in.o procps/built-in.o runit/built-in.o selinux/built-in.o shell/built-in.o sysklogd/built-in.o util-linux/built-in.o util-linux/volume_id/built-in.o -Wl,--end-group -Wl,--start-group -lcrypt -lm -Wl,--end-group
==========
coreutils/lib.a(mktemp.o): In function `mktemp_main':
mktemp.c:(.text.mktemp_main+0xbc): warning: the use of `mktemp' is dangerous, better use `mkstemp'
coreutils/lib.a(touch.o): In function `touch_main':
touch.c:(.text.touch_main+0x1f4): warning: warning: lutimes is not implemented and will always fail
util-linux/lib.a(nsenter.o): In function `nsenter_main':
nsenter.c:(.text.nsenter_main+0x1b4): undefined reference to `setns'
coreutils/lib.a(sync.o): In function `sync_main':
sync.c:(.text.sync_main+0x9c): 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"
make: *** [busybox_unstripped] Error 1

我libm.so的sysroot目录中也有www.example.com。

**编辑:**我也尝试buildroot,但它需要一些关于处理器的信息(例如:endian,详细版本等),我不知道,这是一个黑盒设备,我只在它上开发应用程序,总的信息,我有它运行在BCM 5892,从www.example.com的ARM 11安全处理器broadcom.it运行kenel V 2.6和arm-brcm-linux-gnueabi V4.4.2编译器,我也正确地设置sysroot和交叉编译器前缀,但我怎么知道我使用的libc的版本?

niwlg2el

niwlg2el1#

打开busybox menuconfig并禁用“启用-d和-f标志”

[*] sync (3.8 kb)                                                                                                              
[ ]   Enable -d and -f flags (requires syncfs(2) in libc)

使用较新版本的uclibc(> 0.9.33)可以允许启用该选项。

h4cxqtbf

h4cxqtbf2#

如果您不介意错过busybox的这些特性,那么需要禁用两个功能来解决编译问题。
1.同步的“启用-d和-f标志”
1.恩森特
sync设置可通过menuconfig访问(busybox 1.36):

-> CoreUtils
  -> sync (3.8 kb) (SYNC [=y])
    -> Enable -d and -f flags (requires syncfs(2) in libc)

nsenter可通过menuconfig访问(busybox 1.36):

-> Linux System Utilities
  -> nsenter
6gpjuf90

6gpjuf903#

您可以通过检查此链接目标的名称来检测您的glibc版本:

root@debianxc:/usr/src/busybox# file /opt/STM/STLinux-2.4/devkit/sh4/target/lib/libc.so.6
/opt/STM/STLinux-2.4/devkit/sh4/target/lib/libc.so.6: symbolic link to libc-2.10.2.so
root@debianxc:/usr/src/busybox# file /opt/STM/STLinux-2.4/devkit/sh4/target/lib/ld-linux.so.2
/opt/STM/STLinux-2.4/devkit/sh4/target/lib/ld-linux.so.2: symbolic link to ld-2.10.2.so

这表示glibc版本为2.10.2。但为了确保你也可以这样做:

root@debianxc:/usr/src/busybox# strings /opt/STM/STLinux-2.4/devkit/sh4/target/lib/libc.so.6 | grep '^GLIBC_' | sort | uniq
GLIBC_2.10
GLIBC_2.2
GLIBC_2.2.1
GLIBC_2.2.2
GLIBC_2.2.3
GLIBC_2.2.4
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_PRIVATE
root@debianxc:/usr/src/busybox# strings /opt/STM/STLinux-2.4/devkit/sh4/target/lib/ld-linux.so.2 | grep '^GLIBC_' | sort | uniq
GLIBC_2.2
GLIBC_2.3
GLIBC_2.4
GLIBC_PRIVATE

当我在为SH 4内核www.example.com编译busybox-1.30.1时遇到类似的问题2.6.32.59,我不得不防止nsenter.c和sync.c被Makefile编译。
因此,在您的情况下,您可以尝试更改您的.config文件。

root@debianxc:/usr/src/busybox# diff -d .config_from_defconfig .config
4c4
< # Wed Apr  3 20:04:24 2019
---
> # Wed Apr  3 20:09:45 2019
273c273
< CONFIG_MKTEMP=y
---
> # CONFIG_MKTEMP is not set
304,305c304,305
< CONFIG_SYNC=y
< CONFIG_FEATURE_SYNC_FANCY=y
---
> # CONFIG_SYNC is not set
> # CONFIG_FEATURE_SYNC_FANCY is not set
316,318c316,318
< CONFIG_TOUCH=y
< CONFIG_FEATURE_TOUCH_NODEREF=y
< CONFIG_FEATURE_TOUCH_SUSV3=y
---
> # CONFIG_TOUCH is not set
> # CONFIG_FEATURE_TOUCH_NODEREF is not set
> # CONFIG_FEATURE_TOUCH_SUSV3 is not set
667c667
< CONFIG_NSENTER=y
---
> # CONFIG_NSENTER is not set

以下是您可以遵循的步骤:

#Backup your .config
cp .config .config.backup

#Create a new config with this sed command. You will see its effect by the follow-up diff command below...
sed -e '/^\(CONFIG_\)\(\(MKTEMP\)\|\(TOUCH\)\|\(NSENTER\)\|\(SYNC\)\)=.*$/s/^\([^=]*\)=.*$/# \1 is not set/' .config >.newconfig

#With this diff output you will see its effect
diff -d .config .newconfig

#Overwrite current .config with .newconfig
cp .newconfig .config

#Now run make oldconfig, because some disablings need auto-disablings of other depending configs, too...
make oldconfig

#See the effect ...
diff -d .config.old .config

#make clean before re-compiling
make clean

#make busybox with cross-compiler
make CROSS_COMPILE=sh4-linux-

#Your new busybox is located in your working direktory

#Optionally invoke make install to create dir tree with symlinks
make CROSS_COMPILE=sh4-linux- install

#Tree's name is _install

希望这能帮上忙。

相关问题