交叉编译找不到crt1.o文件

3

你好,我正在编译Linux from Scratch(www.linuxfromscratch.org),现在需要编译一个测试C程序来检查编译是否成功,但是失败了。
我使用的命令如下:

echo "main(){}" > dummy.c
$LFS_TGT-gcc -B/tools/lib dummy.c
readelf -l a.out | grep ': /tools'

在运行第二行代码时,编译器返回以下结果。
..path../bin/ld: cannot find crt1.o: No such file or directory
..path../bin/ld: cannot find crti.o: No such file or directory
..path../bin/ld: cannot find -lc
..path../bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status

不确定问题出在哪里以及如何解决,
到目前为止,我已经重新安装了gcc包和specs文件。

$LFS_TGT-gcc -v -B/tools/lib dummy.c的输出结果为:

Reading specs from /mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/specs
COLLECT_GCC=x86_64-lfs-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/mnt/lfs/tools/bin/../libexec/gcc/x86_64-lfs-linux-gnu/4.6.1/lto- wrapper
Target: x86_64-lfs-linux-gnu
Configured with: ../gcc-4.6.1/configure --target=x86_64-lfs-linux-gnu --prefix=/tools --disable-nls --disable-shared --disable-multilib --disable-decimal-float --disable-threads --disable-libmudflap --disable-libssp --disable-libgomp --disable-libquadmath --disable-target-libiberty --disable-target-zlib --enable-languages=c --without-pppl --without-cloog --with-mpfr-include=/mnt/lfs/sources/gcc-4.6.1/mpfr/src --with-mpfr-lib=/mnt/lfs/sources/gcc-build/mpfr/src/.libs
Thread model: single
gcc version 4.6.1 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-B' '/tools/lib' '-mtune=generic' '-march=x86-64'
 /mnt/lfs/tools/bin/../libexec/gcc/x86_64-lfs-linux-gnu/4.6.1/cc1 -quiet -v -iprefix  /mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/ -isystem /tools/include dummy.c quiet -dumpbase dummy.c -mtune=generic -march=x86-64 -auxbase dummy -version -o /tmp/ccQMiBtT.s
GNU C (GCC) version 4.6.1 (x86_64-lfs-linux-gnu)
    compiled by GNU C version 4.5.2, GMP version 5.0.2, MPFR version 3.1.0, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/sys-include"
ignoring nonexistent directory "/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/include"
ignoring duplicate directory "/mnt/lfs/tools/bin/../lib/gcc/../../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/include"
ignoring duplicate directory "/mnt/lfs/tools/bin/../lib/gcc/../../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/include-fixed"
ignoring nonexistent directory "/mnt/lfs/tools/bin/../lib/gcc/../../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/sys-include"
ignoring nonexistent directory "/mnt/lfs/tools/bin/../lib/gcc/../../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /tools/include
 /mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/include
 /mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/include-fixed
End of search list.
GNU C (GCC) version 4.6.1 (x86_64-lfs-linux-gnu)
    compiled by GNU C version 4.5.2, GMP version 5.0.2, MPFR version 3.1.0, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ac76a9fc3d8568635f4cf190a73f3235
COLLECT_GCC_OPTIONS='-v' '-B' '/tools/lib' '-mtune=generic' '-march=x86-64'
 /mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/bin/as --64 -o /tmp/ccjUV0Gs.o /tmp/ccQMiBtT.s
COMPILER_PATH=/tools/lib/:/mnt/lfs/tools/bin/../libexec/gcc/x86_64-lfs-linux-gnu/4.6.1/:/mnt/lfs/tools/bin/../libexec/gcc/:/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/bin/
LIBRARY_PATH=/tools/lib/:/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/:/mnt/lfs/tools/bin/../lib/gcc/:/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/lib/
COLLECT_GCC_OPTIONS='-v' '-B' '/tools/lib' '-mtune=generic' '-march=x86-64'
 /mnt/lfs/tools/bin/../libexec/gcc/x86_64-lfs-linux-gnu/4.6.1/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /tools/lib64/ld-linux-x86-64.so.2 crt1.o crti.o /mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/crtbegin.o -L/tools/lib -L/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1 -L/mnt/lfs/tools/bin/../lib/gcc -L/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/lib /tmp/ccjUV0Gs.o -lgcc -lc -lgcc /mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/crtend.o crtn.o
/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory
/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/bin/ld: cannot find crti.o: No such file or directory
/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/bin/ld: cannot find -lc
/mnt/lfs/tools/bin/../lib/gcc/x86_64-lfs-linux-gnu/4.6.1/../../../../x86_64-lfs-linux-gnu/bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status

我知道这段话很长,但如果有人能告诉我哪些内容是相关的,我会把它们剪裁下来。说实话,我不知道哪些是有用的。


如果缺少 --with-lib-path=/tools/lib,这也可能发生,因为 ld 不知道要添加 -L/tools/lib - user246672
可能是重复的问题:编译问题:找不到crt1.o - user2284570
4个回答

7

crt1.o、crti.o和crtn.o以及libc.a都是随glibc一起提供的。

你需要为目标系统编译并安装glibc,看起来是在/tools/lib中安装。

编辑:不一定是glibc,而是你正在使用的任何libc。


我已经编译了glibc...但我会重新编译以查看是否有所帮助。 - Drew Galbraith
感谢您的帮助...结果发现我的问题是在没有使用sudo的情况下调用了make install。重新安装清理了一切。谢谢!50个声望即将到来。 - Drew Galbraith

3
如果重新编译gcc不是一个选项,因为它已经与sysroot安装在一起,那么请尝试以下方法:
`export CFLAGS="--sysroot=<your-gcc-sysroot>"`

(提示: libc.so.x 位于 <your-gcc-sysroot>/lib 中)

然后编辑您的 makefile,并替换任何已过时或无效的库路径,确保它们指向正确的位置。

`CFLAGS=BLA-BLA`
`CPPFLAGS=BLA-BLA`

与之配合使用

CFLAGS+=BLA-BLA CPPFLAGS+=BLA-BLA


2

传递-v参数给您的$LFS_TGT-gcc,以了解正在发生的情况。


-v 标志将向您显示 gcc 正在运行的程序,特别是它将显示如何调用 ld,因此您将了解出了什么问题。 - Basile Starynkevitch
我发布了命令的冗长输出,我不确定哪一部分是相关的,所以我全部发布了。 - Drew Galbraith

1
我遇到了以下问题:
root@gccc# arm-wrs-linux-gnueabi-gcc x.c
/opt/tools/wrl3.GA/wrlinux-3.0/layers/wrll-toolchain-4.3-85/arm/toolchain/x86-linux2/bin/../lib/gcc/arm-wrs-linux-gnueabi/4.3.2/../../../../arm-wrs-linux-gnueabi/bin/ld: crt1.o: No such file: No such file or directory
collect2: ld returned 1 exit status
root@gccc# 

因此,当我进行研究时,发现我无法在正确的路径中找到sysroot。因此,我在命令行上指定了sysroot,问题得到了解决:

root@gccc# arm-wrs-linux-gnueabi-gcc x.c --sysroot=/opt/tools/wrl3.GA/sysroot.2011_05_31.18_29_24/arm11_le-glibc_small/sysroot/ -o exe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接