art vanderlay art vanderlay - 1 year ago 86
Linux Question

dont understand gcc --with-local-prefix, --with-native-system-header-dir=

I am compiling gcc and reading manual from

it spcifies

--with-local-prefix=dirname Specify the installation directory for local include files. The default is /usr/local. Specify this option if
you want the compiler to search directory dirname/include for locally
installed header files instead of /usr/local/include.

I take this to mean that when compiling other binaries with this version of GCC it will check this director before the deafult

--with-sysroot=dir Tells GCC to consider dir as the root of a tree that contains (a subset of) the root filesystem of the target
operating system. Target system headers, libraries and run-time object
files will be searched for in there. More specifically, this acts as
if --sysroot=dir was added to the default options of the built
If you specify the --with-native-system-header-dir=dirname option then
the compiler will search that directory within dirname for native
system headers rather than the default /usr/include.

To compile GCC 5.4.0 I
yum install gcc gcc-c++
(ie 4.8.0) and this places headers such as
. After I have complied GCC 5.4.0 and specify it to complie anther binary, the 5.4.0 seems to use the 4.8.0 headers in
instead of the ones created during the 5.4.0 compile.

What I am really asking is, if I want to compile GCC (5.4.0) and have the
make install
install headers as well as GCC & G++ etc in to a custom folder, what options do I set? is my configure for compiling GCC 5.4.0 correct?

/home/myuser/gcc-5.4.0/configure --prefix=/home/gcc540 --disable-multilib --with-system-zlib --enable-languages=c,c++ --with-local-prefix=/home/myotherbin/local --with-gxx-include-dir=/home/gcc540/header

  1. --prefix=/home/gcc540
    set master directory
    make install

  2. --prefix=/home/gcc540/bin
    make install
    will install binaries (gcc, g++ etc)

  3. --prefix=/home/gcc540/lib
    make install
    will install libs

  4. --with-gxx-include-dir=/home/gcc540/headers
    make install
    will install headers for

  5. --with-local-prefix=/home/otherprogs
    (libs,headers from other dependencies are searched here first) ie this is where I would put x264 headers if I was compiling ffmpeg

so what goes in

Additionally, after I have exported to
I have
that includes the following code,

#include <tr1/cstdio>

this causes an error as both
are in the same folder, should
be copied to the parent folder, or is best practice just to pass both
-I/home/gcc540/headers/tr1` to gcc 5.4.0?

Answer Source

The --with-sysroot option is only useful when you build a cross-compiler : the resulting, built gcc will know where to find the target platform's headers and libraries (i.e. it will have a default value for the --sysroot option). The --with-native-system-header-dir is a refinement of the --with-sysroot option and allows to specify a directory relative to the one specified for --with-sysroot where native platform headers will be found. GCC distinguishes its own headers (the ones it copies as part of make install) from the "native" headers that are provided by the operating system itself and were already there regardless of the GCC install.