I'm trying to compile GCC 4.8.3. I have read the documentation carefully but I'm still unable to cross compile it for 64bit system. I have also gone through this guide. But my requirement is to build GCC in /tmp/xxx directory. But the --with-sysroot & --with-native-system-header-dir flags are messing up the compilation. According to the documentation of GCC, I need to use --with-sysroot flag along with --with-native-system-header-dir.

--with-system-header-dir accepts a directory name where the header files are installed. In my case it is ${TOOLS_DIR} and this should be an absolute path, which it is. And, --with-sysroot requires the root path of the folder where the compilation is being done. In my case, it is ${INSTALL_DIR}.


According to the Linuxfromscratch guide, I should create a folder on the root system of the host. But in order to do that I will need sudo permission which I don't have. So, I thought to compile GCC in a subdirectory rather than what was mentioned in the book (because all the users get read/write permission for /tmp directory).

Now, GCC stops with an error that it cannot find the system header directory. And, it tries to search in /tmp/gcc-compile/tmp/gcc-compile/tools/include, which is the wrong path.

The options that I have used are:

sed -i "s#/tools#${TOOLS_DIR}#g" ../gcc-4.8.3-pure64_specs-1.patch

patch -Np1 -i ../gcc-4.8.3-branch_update-1.patch
patch -Np1 -i ../gcc-4.8.3-pure64_specs-1.patch

printf '\n#undef STANDARD_STARTFILE_PREFIX_1\n#define STANDARD_STARTFILE_PREFIX_1 "%s/lib/"\n' "${TOOLS_DIR}" >> gcc/config/linux.h
printf '\n#undef STANDARD_STARTFILE_PREFIX_2\n#define STANDARD_STARTFILE_PREFIX_2 ""\n' >> gcc/config/linux.h

mkdir   "${BUILD_DIR}"  &&
cd      "${BUILD_DIR}"  &&

AR=ar LDFLAGS="-Wl,-rpath,${CROSS_DIR}/lib"   \
../configure --prefix=${CROSS_DIR}            \
             --build=${HOST}                  \
             --target=${TARGET}               \
             --host=${HOST}                   \
             --with-sysroot=${INSTALL_DIR}    \
             --with-local-prefix=${TOOLS_DIR} \
             --with-native-system-header-dir=${TOOLS_DIR}/include \
             --disable-nls                    \
             --disable-static                 \
             --enable-languages=c,c++         \
             --enable-__cxa_atexit            \
             --enable-threads=posix           \
             --disable-multilib               \
             --with-mpc=${CROSS_DIR}          \
             --with-mpfr=${CROSS_DIR}         \
             --with-gmp=${CROSS_DIR}          \
             --with-cloog=${CROSS_DIR}        \
             --with-isl=${CROSS_DIR}          \
             --with-system-zlib               \
             --enable-checking=release        \

While setting the options, I have written ${TOOLS_DIR}/include, then why is it the GCC is trying to look into ${INSTALL_DIR}/${TOOLS_DIR}/include? Can somebody direct me in the right direction?


The directory that should contain system headers does not exist:
make[2]: *** [stmp-fixinc] Error 1
make[2]: *** Waiting for unfinished jobs....
rm gcc.pod
make[2]: Leaving directory `/tmp/gcc-compile/cross-compile-tools/gcc-    final/gcc-4.8.3/gcc-build/gcc'
make[1]: *** [all-gcc] Error 2
make[1]: Leaving directory `/tmp/gcc-compile/cross-compile-tools/gcc-final/gcc-4.8.3/gcc-build'
make: *** [all] Error 2
  • Please post output up to where make stopped with *** Error [x] ... line. – user140866 Jun 4 '16 at 17:05

The --with-native-system-header-dir option takes a relative path from the dir specified with the --with-sysroot option. So to make it work as intended, you need to pass --with-sysroot=${INSTALL_DIR} --with-native-system-header-dir=tools/include

  • I tried that too. It still gives me the same error. – Abhimanyu Saharan Jun 22 '16 at 6:12
  • Did you restart it all from scratch? – Johan Boulé Jun 22 '16 at 7:06
  • Yes, I cleaned up everything before trying again. – Abhimanyu Saharan Jun 22 '16 at 8:19

I fixed this with a soft link in sysroot.


pushd ${INSTALL_DIR}
mkdir -p ./${INSTALL_DIR}
ln -s ../(number of dirs up)/include include

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.