Now that GCC is configured, you are ready to build the compiler and runtime libraries.
We highly recommend that GCC be built using GNU make; other versions may work, then again they might not.
(For example, many broken versions of make will fail if you use the recommended setup where objdir is different from srcdir. Other broken versions may recompile parts of the compiler when installing the compiler.)
Some commands executed when making the compiler may fail (return a
non-zero status) and be ignored by make
. These failures, which
are often due to files that were not found, are expected, and can safely
be ignored.
It is normal to have compiler warnings when compiling certain files. Unless you are a GCC developer, you can generally ignore these warnings unless they cause compilation to fail.
On certain old systems, defining certain environment variables such as
CC
can interfere with the functioning of make
.
If you encounter seemingly strange errors when trying to build the compiler in a directory other than the source directory, it could be because you have previously configured the compiler in the source directory. Make sure you have done all the necessary preparations.
If you build GCC on a BSD system using a directory stored in an old System
V file system, problems may occur in running fixincludes
if the
System V file system doesn't support symbolic links. These problems
result in a failure to fix the declaration of size_t
in
sys/types.h
. If you find that size_t
is a signed type and
that type mismatches occur, this could be the cause.
The solution is not to use such a directory for building GCC.
When building from CVS or snapshots, or if you modify parser sources, you need the Bison parser generator installed. Any version 1.25 or later should work; older versions may also work. If you do not modify parser sources, releases contain the Bison-generated files and you do not need Bison installed to build them.
When building from CVS or snapshots, or if you modify Texinfo documentation, you need version 4.0 or later of Texinfo installed if you want Info documentation to be regenerated. Releases contain Info documentation pre-built for the unmodified documentation in the release.
For a native build issue the command make bootstrap
. This
will build the entire GCC system, which includes the following steps:
If you are short on disk space you might consider make
bootstrap-lean
instead. This is identical to make
bootstrap
except that object files from the stage1 and
stage2 of the 3-stage bootstrap of the compiler are deleted as
soon as they are no longer needed.
If you want to save additional space during the bootstrap and in
the final installation as well, you can build the compiler binaries
without debugging information with make CFLAGS='-O' LIBCFLAGS='-g
-O2' LIBCXXFLAGS='-g -O2 -fno-implicit-templates' bootstrap
. This will save
roughly 40% of disk space both for the bootstrap and the final installation.
(Libraries will still contain debugging information.)
If you wish to use non-default flags when compiling the stage2 and
stage3 compile, set BOOT_CFLAGS
on the command line when doing
make bootstrap
. Non-default optimization flags are less well
tested here than the default of -g -O2
, but should still work.
In a few cases, you may find that you need to specify special flags such
as -msoft-float
here to complete the bootstrap; or, if the
native compiler miscompiles the stage1 compiler, you may need to work
around this, by choosing BOOT_CFLAGS
to avoid the parts of the
stage1 compiler that were miscompiled, or by using make
bootstrap4
to increase the number of stages of bootstrap.
If you used the flag --enable-languages=...
to restrict
the compilers to be built, only those you've actually enabled will be
built. This will of course only build those runtime libraries, for
which the particular compiler has been built. Please note,
that re-defining LANGUAGES when calling make bootstrap
does not work anymore!
If the comparison of stage2 and stage3 fails, this normally indicates
that the stage 2 compiler has compiled GCC incorrectly, and is therefore
a potentially serious bug which you should investigate and report. (On
a few systems, meaningful comparison of object files is impossible; they
always appear "different". If you encounter this problem, you will
need to disable comparison in the Makefile
.)
We recommend reading the crossgcc FAQ for information about building cross compilers.
When building a cross compiler, it is not generally possible to do a 3-stage bootstrap of the compiler. This makes for an interesting problem as parts of GCC can only be built with GCC.
To build a cross compiler, we first recommend building and installing a native compiler. You can then use the native GCC compiler to build the cross compiler.
Assuming you have already installed a native copy of GCC and configured
your cross compiler, issue the command make
, which performs the
following steps:
Note that if an error occurs in any step the make process will exit.
If you have a multiprocessor system you can use make bootstrap
MAKE="make -j 2" -j 2
or just make -j 2 bootstrap
for GNU Make 3.79 and above instead of just make bootstrap
when building GCC. You can use a bigger number instead of two if
you like. In most cases, it won't help to use a number bigger than
the number of processors in your machine.