https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87769
--- Comment #4 from Mateusz Zych <mte.zych at gmail dot com> --- Right, the "--with-sysroot=" configuration parameter is the key. The sysroot directory defines minimal filesystem of a target machine, in particular it should contain standard C library and Linux kernel headers, so it makes sense that I have to provide the sysroot directory to build standalone GCC, which would be a cross compiler. However, I don't understand why would configuration parameters "--host=" and "--target=", define whether I am building a cross compiler or not. To me, what differentiates cross compiler form native compiler, is the location of libraries and headers. - Native compilers use libraries and headers from host machine. - Cross compilers never touch host machine and always use sysroot. Of course, all compilers targeting different architecture compared to architecture of the host machine have be cross compilers. But the opposite is not true - not all cross compilers have to target architecture different from architecture of the host machine. They can match, no problem! And this is exactly what I'm trying to do - I want build GCC cross compiler targeting the exact same architecture that my host machine is using. OK, with that out of the way, I've updated my script: # Linux wget https://kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.gz tar -xvf linux-4.19.tar.gz mv linux-4.19 linux-source cd linux-source make ARCH=x86_64 INSTALL_HDR_PATH=$PWD/../gcc/sysroot/usr headers_install cd .. # GNU C Library (glibc) wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz tar -xvf glibc-2.28.tar.gz mv glibc-2.28 glibc-source mkdir glibc-build cd glibc-build ../glibc-source/configure --build=x86_64-linux-gnu \ --host=x86_64-linux-gnu \ --target=x86_64-linux-gnu \ --prefix=$PWD/../gcc/sysroot/usr \ --with-headers=$PWD/../gcc/sysroot/usr/include \ --disable-multilib \ --disable-nls \ --disable-timezone-tools make all -j 4 make install cd .. # GNU Binutils wget https://ftp.gnu.org/gnu/binutils/binutils-2.31.tar.gz tar -xvf binutils-2.31.tar.gz mv binutils-2.31 binutils-source mkdir binutils-build cd binutils-build ../binutils-source/configure --build=x86_64-linux-gnu \ --host=x86_64-linux-gnu \ --target=x86_64-linux-gnu \ --prefix=$PWD/../gcc \ --with-sysroot=$PWD/../gcc/sysroot \ --disable-multilib \ --disable-nls make all -j 4 make install cd .. # GCC wget https://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz tar -xvf gcc-8.2.0.tar.gz mv gcc-8.2.0 gcc-source cd gcc-source ./contrib/download_prerequisites cd .. mkdir gcc-build cd gcc-build ../gcc-source/configure --build=x86_64-linux-gnu \ --host=x86_64-linux-gnu \ --target=x86_64-linux-gnu \ --prefix=$PWD/../gcc \ --with-sysroot=$PWD/../gcc/sysroot \ --enable-languages=c,c++ \ --disable-multilib \ --disable-nls make all -j 4 make install cd .. Essentially I am puting: - GCC and Binutils into $ROOT/gcc and - glibc with Linux headers into ROOT/gcc/sysroot. Unfortunately with updated script, GCC is not compiling anymore. :( I've never managed to compile GCC configured with parameter "--with-sysroot=". What is actually failing? Well, the libgcc_s.so fails to link with libc.so.6: attempt to open /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/libc.so.6 failed attempt to open /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/libc_nonshared.a failed attempt to open /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot/home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/ld-linux-x86-64.so.2 failed /usr/bin/ld: cannot find /home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/libc.so.6 inside /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot /usr/bin/ld: cannot find /home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/libc_nonshared.a inside /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot /usr/bin/ld: cannot find /home/mzych/standalone-gcc/glibc-build/../gcc/sysroot/usr/lib/ld-linux-x86-64.so.2 inside /home/mzych/standalone-gcc/gcc-build/../gcc/sysroot To me this failure looks like an issue with sysroot path, because the sysroot path is appended twice. I would be very grateful if somebdy could help me understand how to build GCC using "--with-sysroot=" configuration option. Thank you, Mateusz