交叉编译找不到crt1.o

发布于 2024-12-12 12:09:53 字数 5211 浏览 5 评论 0原文

您好,我正在从头开始编译 Linux (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 软件包以及规范文件。

$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

我意识到它非常长,但如果有人告诉我相关的内容,我会修剪它。因为老实说我不知道​​什么有用。

Hi I am compiling Linux from Scratch (www.linuxfromscratch.org) and I am on a step that requires my to compile a test c program to see if the compilation is working and it is failing.
The commands I am using are:

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

When running the second line, the compiler returns the following

..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

Not sure what the problem is here and how to fix it,
So far I have reinstalled the gcc package as well as the specs file.

The output of $LFS_TGT-gcc -v -B/tools/lib dummy.c is:

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

I realize that it is super long but if someone would tell what is relevant I will trim it. Because quite honestly I don't know whats useful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

疏忽 2024-12-19 12:09:53

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

您需要为您的目标系统编译 glibc,并从外观上看安装在 /tools/lib 中。

编辑:不一定是 glibc,但无论你使用什么 libc。

crt1.o, crti.o and crtn.o and libc.a all come with your glibc.

You need to have glibc compiled for your target system and installed, from the looks of it, in /tools/lib.

EDIT: Not necessarily glibc, but whatever libc you're using.

谜兔 2024-12-19 12:09:53

如果重新编译 gcc 不是一个选项,因为它已经随 sysroot 安装,那么请尝试以下操作:(

`export CFLAGS="--sysroot=<your-gcc-sysroot>"`

提示:libc.so.x 位于 /lib< /code>)

然后编辑您的 makefile 并将其替换

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

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

If recompiling gcc is not an option because it is already installed with sysroot, then try this:

`export CFLAGS="--sysroot=<your-gcc-sysroot>"`

(hint: libc.so.x is in <your-gcc-sysroot>/lib)

Then edit your makefile and replace any

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

with

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

-v 传递给您的 $LFS_TGT-gcc 以了解发生了什么。

Pass -v to your $LFS_TGT-gcc to understand what is happening.

过气美图社 2024-12-19 12:09:53

我面临以下问题:

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

I was facing the following problem:

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# 

So when I researched it I found out that I was not able to find out the sysroot in the correct path. So I specified the sysroot on the command line and my problem was solved:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文