c - MIPS GCC 交叉编译器构建失败 : "cannot find -lc"

标签 c linux gcc cross-compiling uclibc

我正在尝试使用 Linux 2.6.31 为基于 QCA955X 的路由器设置 GCC 4.9.4 交叉编译器。这是一个使用 uClibc-0.9.30.1 的 MIPS32R2-abi CPU(在 /lib 中找到。)因此,我决定编译 GCC 4.x使用匹配的 uClibc 和 binutils-2.19.1a。我的主机系统是 Ubuntu 18.04,Linux 4.17-rc5 和 gcc 版本 7.3.0 (Ubuntu 7.3.0-16ubuntu3)

~/mips-cross-gcc/staging_dir 是我的前缀,~/mips-cross-gcc/staging_dir/sysroot 是我系统的临时 sysroot。

1) 我下载了binutils-2.19.1a.tar.bz2gcc-4.9.4.tar.bz2linux-2.6.31.9。 tar.xzuClibc-0.9.30.1.tar.bz2~/mips-cross-gcc/sources

2) 我解压了所有源代码。

3) 安装 linux 头文件:

make ARCH=mips INSTALL_HDR_PATH=/home/user/mips-cross-gcc/staging_dir/sysroot/usr headers_install

4) 构建 binutils:

cd binutils-2.19.1
./configure --prefix=/home/user/mips-cross-gcc/staging_dir --target=mips-linux-uclibc --disable-multilib --disable-werror --enable-shared --without-newlib --with-sysroot=/home/user/mips-cross-gcc/staging_dir/sysroot --enable-languages=c,c++ --disable-libgomp

make all-binutils
make all-ld
make all-gas
make install-binutils
make install-ld
make install-gas

5) 构建“阶段 1”gcc,以引导 uClibc:

cd gcc-4.9.4
mkdir -p build/gcc-stage1
../../configure --target=mips-linux-uclibc --prefix=/home/user/mips-cross-gcc/staging_dir --disable-werror --disable-libgomp --without-newlib --disable-multilib --enable-languages=c,c++ --enable-shared --disable-__cxa_atexit --enable-target-optspace --disable-nls --disable-libmudflap  --disable-libssp --with-float=soft --with-sysroot=/home/user/mips-cross-gcc/staging_dir/sysroot --with-gnu-ld --without-headers
make all-gcc
make install-gcc

6) 安装 uClibc 头文件:

cd uClibc-0.9.30.1
make PREFIX=/home/user/mips-cross-gcc/staging_dir/sysroot install_headers

7) 为目标架构构建 libgcc: 光盘 gcc-4.9.4 制作所有目标 libgcc

Libgcc 一直编译到最后的 libgcc_s 链接阶段:

/home/daniel/mips-cross-gcc/staging_dir/mips-linux-uclibc/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
Makefile:937: recipe for target 'libgcc_s.so' failed

我认为引导 GCC 不需要 libc,因为它还没有被编译,对吧?我做错了什么?我将使用这个已编译的 GCC 来构建 uClibc,然后我将使用我的新 uClibc 再次编译 GCC,以便我可以交叉编译软件. GCC 在第一个构建中需要 libc 这一事实似乎是错误的。

我尝试使用第一个 gcc 而不编译 libgcc 来构建 uClibc,但我几乎立即收到:

LD ld-uClibc-0.9.30.1.so
mips-linux-uclibc-gcc: error: libgcc.a: No such file or directory
ldso/ldso/Makefile.in:54: recipe for target 'lib/ld-uClibc.so' failed

因此,uClibc 需要 libgcc 来链接自身,而 gcc 需要一个 libc(任何类型,包括 uClibc) 来链接它自己的 libgcc。这似乎是一个先有鸡还是先有蛋的问题。如何解决这个问题?

最佳答案

我修好了。显然,GCC 必须在没有启用共享库(--disable-shared)的情况下构建,这样它就不会动态链接生成的库,如 libgcc(即 >libc,) 但还是不行。 -lc 仍然没有找到。

我又进行了一些谷歌搜索,发现了来自 eglibc 的有用信息,关于使用 gcc 制作他们自己的工具链:eglibc.org

The First GCC

For our work, we need a cross-compiler targeting a PowerPC Linux system. However, that configuration includes the shared library 'libgcc_s.so', which is compiled against the EGLIBC headers (which we haven't installed yet) and linked against 'libc.so' (which we haven't built yet).

Fortunately, there are configuration options for GCC which tell it not to build 'libgcc_s.so'. The '--without-headers' option is supposed to take care of this, but its implementation is incomplete, so you must also configure with the '--with-newlib' option. While '--with-newlib' appears to mean "Use the Newlib C library", its effect is to tell the GCC build machinery, "Don't assume there is a C library available."

看起来经过足够多的挖掘,一定有人会找到确切的问题所在。

简而言之,将 --enable-shared 更改为 --disable-shared 并将 --with-newlib 添加到 GCC 的 ./configure 解决了这个问题并编译并链接了一个我用来编译 uClibc 的 libgcc_s.so,然后使用来自 uClibc 的新生成的 libc 重新编译了 gcc。实际上,可以在 2018 GCC 7.x 上使用 2011 uClibc 编译 2016 GCC 4.x。

关于c - MIPS GCC 交叉编译器构建失败 : "cannot find -lc",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50645332/

相关文章:

python - 在 Python 中加速矩阵 vector 乘法和求幂,可能通过调用 C/C++

linux - 有没有工具可以计算处理器每个核心的能耗?

linux - sed - 使用数组构建正则表达式

gcc - 为什么 gcc 不从命令行传递宏值?

c - 反汇编 C 函数的 IA32 32 位 AT&T 汇编代码

c++ - fread/fwrite 大小和计数

c++ - C++ FAQ的不安全宏解释?

c - C 预处理器如何处理循环依赖?

c++ - gcc 是否支持带 -fexceptions 的 -static-libgcc?

c - mmix 上 gcc 的 Printf 问题