2011-10-28 105 views
3

嗨,我編譯從頭開始的Linux(www.linuxfromscratch.org),我對我的要求編寫測試C程序,看是否編譯工作的一步,它失敗。
我使用的命令是:交叉編譯找不到crt1.o

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 

我意識到這是超長的,但如果有人能告訴什麼是相關的,我會修剪。因爲老實說,我不知道什麼是有用的。

+0

這也可能發生,如果'--with-LIB路徑= /工具/ lib'丟失,因爲LD不知道要加'-L /工具/ lib'的 – Barry

+0

可能重複[編譯問題:找不到crt1.o(http://stackoverflow.com/questions/6329887/compiling-problems-cannot-find-crt1-o) – user2284570

回答

5

crt1.o,crti.o和crtn.o和libc.a都帶有你的glibc。

你需要有glibc的編譯你的目標系統並安裝,從外觀上來看,在/ tools/lib目錄。

編輯:不一定glibc,但無論你使用的libc。

+0

我已經編譯了glibc ...但是病態重做,看它是否有幫助。 –

+0

感謝您的幫助...事實證明我的問題是沒有sudo調用'make install'。全新的安裝清理了一切。謝謝! 50代表你的方式。 –

2

通行證-v$LFS_TGT-gcc明白髮生了什麼。

+0

的 - v標誌會顯示你想要的程序gcc正在運行,特別是它會顯示ld是如何被調用的,所以你會明白什麼是錯的。 –

+0

我發佈了命令的詳細輸出,我不確定哪些部分是相關的,所以我發佈了所有內容。 –

2

如果重新編譯GCC是不是因爲它已與SYSROOT安裝選項,然後試試這個:

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

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

然後編輯生成文件,並更換

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

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

0

我面臨着以下問題:

[email protected]# 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 
[email protected]# 

所以,當我研究它,我發現我無法找出正確的路徑SYSROOT。所以我的命令行上SYSROOT,我的問題解決了:

[email protected]# 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