How to solve the relationship between gcc and glibc when building cross compiler toolchain?

Matthew Fortune Matthew.Fortune@imgtec.com
Wed Jul 1 21:59:00 GMT 2015


jpcstpj7281 <jpcstpj7281@126.com> writes:
> Recently, I've tried to build a cross compiler toolchain for MIPS architecture.
> 
> Firstly, I've exported these variables to environment settings and created some folders:
> 
> export PRJROOT=$(pwd)
> export TARGET=mips-linux
> export PREFIX=$PRJROOT/tools
> export TARGET_PREFIX=$PREFIX/$TARGET
> export PATH=$PREFIX/bin:$PATH
> 
> mkdir -p kernel source tools
> mkdir -p build-tools/binutils
> mkdir -p build-tools/gcc-bootstrap
> mkdir -p build-tools/gcc
> mkdir -p build-tools/glibc
> mkdir -p build-tools/gdb
> Secondly, I've installed the pre-required libraries:
> 
> sudo apt-get install build-essential
> sudo apt-get install autoconf libtool m4 bison flex texinfo
> sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev
> sudo apt-get install gawk
> Then, I've build the binutils-2.25 with the following command:
> 
> $PRJROOT/source/binutils-2.25/configure \
>     --target=$TARGET \
>     --prefix=$PREFIX \
>     --disable-werror
> make -j 4
> make install
> But when building the bootstrap gcc with the following configuration and command, it got a
> error message:
> 
> $PRJROOT/source/gcc-5.1.0/configure \
>     --target=$TARGET \
>     --prefix=$PREFIX \
>     --enable-shared \
>     --enable-languages=c \
>     --without-headers \
>     --with-gnu-ld \
>     --with-gnu-as \
>     --disable-decimal-float \
>     --disable-libgomp \
>     --disable-libmudflap \
>     --disable-libssp \
>     --disable-threads \
>     --disable-multilib \
>     --disable-libquadmath \
>     --disable-libatomic \
>     --with-newlib

You probably don't want the last line.

> The gcc-bootstrap error message is:
> 
> .../tools/mips-linux/bin/ld: cannot find crti.o
> .../tools/mips-linux/bin/ld: cannot find -lc
> .../tools/mips-linux/bin/ld: cannot find crtn.o
> collect2: error: ld return 1
> make[2]: *** [libgcc_s.so] error 1
> Once I change the configuration --enable-shared to --disable-shared, the gcc-bootstrap
> will build successfully.

Using --disable-shared on the stage 1 is how I am building tools. I have never built
glibc 2.16 only more recent versions but this has worked for me. There are a couple of
things turned off in my normal build script. You didn't say which part of glibc failed
to build?

For glibc my build script disables: "--disable-profile" "--without-gd" "--without-cvs"

I've long since forgotten why these options were put in though I'm afraid.

> 
> And then, when I build glibc using the previous gcc-bootstrap with the following command,
> it get a error message:
> 
> $PRJROOT/source/glibc-2.16.0/configure \
>     --host=$TARGET \
>     --build=$($PRJROOT/source/glibc-2.16.0/scripts/config.guess) \
>     --prefix=$PREFIX \
>     --with-headers=$TARGET_PREFIX/include \
>     --with-binutils=$TARGET_PREFIX/bin \
>     --enable-add-ons \
>     --with-tls \
>     --disable-profile \
>     libc_cv_forced_unwind=yes \
>     libc_cv_ctors_header=yes \
>     libc_cv_c_cleanup=yes
> The glibc error message is:
> 
> .../tools/mips-linux/bin/ld: cannot find -lgcc_s
> collect2: error: ld returned 1 exit status
> As shown above, the gcc-bootstrap compilation with configuration --enable-shared in order
> to build libgcc_s.so needs the file such as crti.o and crtn.o that glibc builds. Once
> changing to --disable-shared, the gcc-bootstrap build successfully and will not build
> libgcc_s.so file. However, when building the glibc, it needs libgcc_s.so file to link. Can
> anyone tell me how to solve the relationship between gcc and glibc as above?

I'm not sure I've been much use as these chicken and egg problems drive me crazy for ages
then I solve them and promptly forget how.

Matthew



More information about the Gcc-help mailing list