交叉编译遇到bin/ld: cannot find crt1.o: No such file or directory问题解决

Posted fanchenxinok

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了交叉编译遇到bin/ld: cannot find crt1.o: No such file or directory问题解决相关的知识,希望对你有一定的参考价值。

交叉编译一个库在运行configure生成Makefile时遇到如下错误:

$ ./configure --host=arm-linux-gnueabihf CC=/home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc --prefix=/usr/local/ncurse --without-ada --enable-termcap --with-shared 

checking for arm-linux-gnueabihf-gcc... /home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc
checking for C compiler default output... configure: error: C compiler cannot create executables

很明显是GCC交叉编译工具校验不过,查看config.log文件的log信息如下:
configure:1711: checking for C compiler default output
configure:1714: /home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc    conftest.c  >&5
/home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/../lib/gcc/arm-linux-gnueabihf/7.2.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find crt1.o: No such file or directory
/home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/../lib/gcc/arm-linux-gnueabihf/7.2.1/../../../../arm-linux-gnueabihf/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status

说找不到crt1.o,这就很奇怪了 因为crt1.o文件在我的sysroot目录下是存在的。

查看下GCC交叉编译工具的prefix目录(红色部分字体)是不存在的,因为可能这个工具是从别人那里拷过来的。

$/home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=/home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/../libexec/gcc/arm-linux-gnueabihf/7.2.1/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: '/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/arm-linux-gnueabihf/snapshots/gcc.git~linaro-7.2-2017.11/configure' SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/arm-linux-gnueabihf/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/arm-linux-gnueabihf/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/arm-linux-gnueabihf/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libmudflap --enable-lto --enable-shared --without-included-gettext --enable-nls --disable-sjlj-exceptions --enable-gnu-unique-object --enable-linker-build-id --disable-libstdcxx-pch --enable-c99 --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --with-float=hard --with-fpu=vfpv3-d16 --with-mode=thumb --with-tune=cortex-a9 --with-arch=armv7-a --enable-threads=posix --enable-multiarch --enable-libstdcxx-time=yes --enable-gnu-indirect-function --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/arm-linux-gnueabihf/_build/sysroots/arm-linux-gnueabihf --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/arm-linux-gnueabihf/_build/builds/destdir/x86_64-unknown-linux-gnu/arm-linux-gnueabihf/libc --enable-checking=release --disable-bootstrap --enable-languages=c,c++,fortran,lto --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabihf --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/arm-linux-gnueabihf/_build/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)

而我编译用到的一些系统头文件和库都在home/joe/worksource/toolchain_sdk_j6entry/sysroots/armv7ahf-neon-linux-gnueabi/目录下,于是在CC的后面加上--sysroot=home/joe/worksource/toolchain_sdk_j6entry/sysroots/armv7ahf-neon-linux-gnueabi/就可以通过了,如下所示:

$./configure --host=arm-linux-gnueabihf CC="/home/joe/worksource/toolchain_sdk_j6entry/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc --sysroot=/home/joe/worksource/toolchain_sdk_j6entry/sysroots/armv7ahf-neon-linux-gnueabi/" --prefix=/usr/local/ncurse --without-ada --enable-termcap --with-shared

特此记录下

以上是关于交叉编译遇到bin/ld: cannot find crt1.o: No such file or directory问题解决的主要内容,如果未能解决你的问题,请参考以下文章

/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lperconaserverclient_r 解决

错误-解决/usr/bin/ld: cannot find -lxxx 问题

错误-解决/usr/bin/ld: cannot find -lxxx 问题

chkrootkit 编译报错的解决/usr/bin/ld: cannot find -lc

chkrootkit 编译报错的解决/usr/bin/ld: cannot find -lc