Introduction to GCC

The GCC package contains GNU compilers. This package is useful for compiling programs written in C, C++, Fortran, Java, Objective C, Objective C++, Ada, and Go. You should ensure you actually need one of these additional compilers (C and C++ are installed in LFS) before you install them. Additionally, there are instructions in the BLFS book to install OpenJDK-, which can be used instead of the Java provided by the GCC package. Many consider the Iced Tea version to be a more robust Java environment than the one provided by GCC.

This package is known to build and work properly using an LFS-7.4 platform.



If you are upgrading GCC from any other version prior to 4.8.1, then you must be careful compiling 3rd party kernel modules. You should ensure that the kernel and all its native modules are also compiled using the same version of GCC that you use to build the 3rd party module. This issue does not affect native kernel (and kernel modules) updates, as the instructions below are a complete reinstallation of GCC. If you have existing 3rd party modules installed, ensure they are recompiled using the updated version of GCC. As always, never update the kernel headers from the ones used when Glibc was compiled during LFS.

Package Information

GCC Dependencies


Required if building java

Zip-3.0, UnZip-6.0, and Which-2.20



If you plan to compile Ada, you will need to install GNAT temporarily to satisfy the circular dependency when you recompile GCC to include Ada. At the AdaCore download page, choose your platform and 2013, then select the file to download. You probably want the x86-linux or x86_64-linux file.

GNAT GPL 2013 Package Information

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/gcc

Installation of GNAT

Before unpacking and changing into the GCC source directory, first unpack the GNAT tarball. You may have to drill down several levels and unpack a second tarball. For example, AdaCore-Download-2013-07-22_0530.tar expands to x86_64-linux/2013/gnatgpl/gnat-gpl-2013-x86_64-pc-linux-gnu-bin.tar.gz. Expand this second tarball and change into the newly created directory. Install GNAT by running the following command:

make ins-all prefix=/opt/gnat

The GNAT compiler can be invoked by executing the gcc binary installed in /opt/gnat/bin.

You may now remove the GNAT source directory if desired.

Prepare to compile GCC by placing the GNAT version of gcc at the beginning of the PATH variable by using the following commands as the root user:

export PATH=/opt/gnat/bin:$PATH_HOLD

Doing so has the drawback that the GCC and Binutils executables are taken from the just installed GNAT package, but the versions of those executables are outdated compared to those installed in LFS. This is not important for the GCC compilers, since they recompile themselves during the bootstrap process. On the other hand, the outdated ld and as tools are used all along. In order to use the LFS tools, issue:

find /opt/gnat -name ld -exec mv -v {} {}.old \;
find /opt/gnat -name as -exec mv -v {} {}.old \;

Installation of GCC

Install GCC by running the following commands:



The installation process may overwrite your existing GCC gcc and c++ compilers and libraries. Having the Tcl, Expect and DejaGnu packages installed before beginning the build is highly recommended so you can run the full suite of tests.

Do not continue with the make install command until you are confident the build was successful. You can compare your test results with those found at http://gcc.gnu.org/ml/gcc-testresults/. You may also want to refer to the information found in the GCC section of Chapter 6 in the LFS book (../../../../lfs/view/7.4/chapter06/gcc.html).

The instructions below let the build machinery perform a “bootstrap” intentionally. This is necessary if you install the Ada compiler anyway. Even if you don't, a bootstrap is recommended for robustness.

sed -i 's/\(install.*:\) install-.*recursive/\1/' libffi/Makefile.in         &&
sed -i 's/\(install-data-am:\).*/\1/'             libffi/include/Makefile.in &&
sed -i 's/install_to_$(INSTALL_DEST) //'          libiberty/Makefile.in      &&
sed -i 's@\./fixinc\.sh@-c true@'                 gcc/Makefile.in            &&

case `uname -m` in
      i?86) sed -i 's/^T_CFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in ;;
esac &&

mkdir ../gcc-build &&
cd    ../gcc-build &&

../gcc-4.8.1/configure          \
    --prefix=/usr               \
    --libdir=/usr/lib           \
    --libexecdir=/usr/lib       \
    --enable-shared             \
    --enable-threads=posix      \
    --enable-__cxa_atexit       \
    --disable-multilib          \
    --disable-bootstrap         \
    --disable-install-libiberty \
    --with-system-zlib          \
    --enable-clocale=gnu        \
    --enable-lto                \
    --enable-languages=c,c++,fortran,ada,go,java,objc,obj-c++ &&

If you have installed additional packages such as valgrind and gdb, the gcc part of the testsuite will run more tests than in LFS. Some of those will report FAIL and others XPASS (pass when expected to FAIL). To run the checks:

ulimit -s 32768 &&
make -k check   &&


Now, as the root user:

make install &&

ln -v -sf ../usr/bin/cpp /lib &&
ln -v -sf gcc /usr/bin/cc     &&

chown -v -R root:root \
    /usr/lib/gcc/*linux-gnu/4.8.1/include{,-fixed} \

You should now remove the GNAT installation and perform other cleanups:

rm -rf /opt/gnat &&
export PATH=$PATH_HOLD &&

Command Explanations

The first two sed commands prevent the installation of the libffi library bundled with GCC, since it is outdated compared to libffi-3.0.13. The three other sed commands are the same ones used during the build of LFS.

mkdir ../gcc-build; cd ../gcc-build: The GCC documentation recommends building the package in a dedicated build directory.

--enable-shared --enable-threads=posix --enable-__cxa_atexit: These parameters are required to build the C++ libraries to published standards.

--disable-multilib: This parameter ensures that files are created for the specific architecture of your computer.

--enable-clocale=gnu: This parameter is a failsafe for incomplete locale data.

--enable-lto: Setting this parameter allows to build a compiler which is able to perform “link time optimization (lto)”.

--enable-languages=c,c++,fortran,java,objc,obj-c++,ada,go: This command identifies which languages to build. You may modify this command to remove undesired languages.

ulimit -s 32768: This command prevents several tests from running out of stack space.

make -k check: This command runs the test suite without stopping if any errors are encountered.

../gcc-4.8.1/contrib/test_summary: This command will produce a summary of the test suite results. You can append | grep -A7 Summ to the command to produce an even more condensed version of the summary. You may also wish to redirect the output to a file for review and comparison later on.

ln -v -sf ../usr/bin/cpp /lib: This command creates a link to the C PreProcessor as some packages expect it to be installed in the /lib directory.

ln -v -sf gcc /usr/bin/cc: This link is created as some packages refer to the C compiler using an alternate name.

chown -v -R root:root /usr/lib/gcc/*linux-gnu/...: If the package is built by a user other than root, the ownership of the installed include and adalib directories (and their contents) will be incorrect. These commands change the ownership to the root user and group . Omit the command changing the Ada directories if you did not include Ada as one of the installed languages.


Installed Programs: aot-compile, gappletviewer, gc-analyze, gccgo, gcj, gcj-dbtool, gcjh, gfortran, gij, gjar, gjarsigner, gjavah, gkeytool, gnat, gnatbind, gnatchop, gnatclean, gnatfind, gnative2ascii, gnatkr, gnatlink, gnatls, gnatmake, gnatname, gnatprep, gnatxref, gorbd, grmic, grmid, grmiregistry, gserialver, gtnameserv, jcf-dump, jv-convert, rebuild-gcj-db, and architecture specific names
Installed Libraries: libgcj_bc.so, libgcj.so, libgcj-tools.so, libgfortran.{so,a}, libgij.so, libgo.{so,a}, libgobegin.a, libobjc.{so,a} and numerous other run-time libraries and executables in /usr/lib/gcc
Installed Directories: /usr/include/c++/4.8.1/{gcj,gnu,java,javax,org,sun}, /usr/lib/gcc/<arch-model>-linux-gnu/4.8.1/ada{include,lib}, /usr/lib/gcj-4.8.1-13, /usr/lib/go, /usr/lib/security, and /usr/share/java

Some program and library names and descriptions are not listed here, but can be found at ../../../../lfs/view/7.4/chapter06/gcc.html#contents-gcc as they were initially installed during the building of LFS.

Short Descriptions


searches a directory for Java bytecode and uses gcj to compile it to native code.


loads and run a Java applet.


analyzes garbage collector (GC) memory dumps from Java code.


is a GCC-based compiler for the Go language.


is an ahead-of-time compiler for the Java language.


is a tool for creating and manipulating class file mapping databases.


generates header files from Java class files.


is the Fortran compiler invoked by gcc.


is the GNU interpreter for Java bytecode.


is an (partial) implementation of the jar utility that comes with Sun's JDK.


is a Java ARchive (JAR) file signing and verification tool.


generates header files from Java class files.


manages private keys and public certificates in a Java environment.


is the Ada compiler invoked by gcc.


is used to bind compiled objects.


is useful for renaming files to meet the standard Ada default file naming conventions.


is used to remove files associated with a GNAT project.


is the GNAT definition/use finder.


is an encoding converter for Java.


is used to determine the crunched name for a given file, when crunched to a specified maximum length.


is used to link programs and build an executable file.


is the compiled unit browser.


is an automatic make facility.


will list the files associated with a GNAT project.


is the GNAT external preprocessor.


is the GNAT cross-referencer.


is an object request broker daemon.


generates stubs for Remote Method Invocation.


RMI activation system daemon.


starts a remote object registry on the current host.


prints the serialVersionUID of the specified class.


starts a naming service.


prints information about Java class files.


converts files from one encoding to another.


Merge the per-solib databases made by aot-compile into one system-wide database.

Last updated on 2013-09-05 20:07:58 -0700