]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/install/building/building-a-cross-compiler.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / install / building / building-a-cross-compiler.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6Building a cross compiler
7*************************
8
9When building a cross compiler, it is not generally possible to do a
103-stage bootstrap of the compiler. This makes for an interesting problem
11as parts of GCC can only be built with GCC.
12
13To build a cross compiler, we recommend first building and installing a
14native compiler. You can then use the native GCC compiler to build the
15cross compiler. The installed native compiler needs to be GCC version
162.95 or later.
17
18Assuming you have already installed a native copy of GCC and configured
19your cross compiler, issue the command :command:`make`, which performs the
20following steps:
21
22* Build host tools necessary to build the compiler.
23
24* Build target tools for use by the compiler such as binutils (bfd,
25 binutils, gas, gprof, ld, and opcodes)
26 if they have been individually linked or moved into the top level GCC source
27 tree before configuring.
28
29* Build the compiler (single stage only).
30
31* Build runtime libraries using the compiler from the previous step.
32
33Note that if an error occurs in any step the make process will exit.
34
35If you are not building GNU binutils in the same source tree as GCC,
36you will need a cross-assembler and cross-linker installed before
37configuring GCC. Put them in the directory
38:samp:`{prefix}/{target}/bin`. Here is a table of the tools
39you should put in this directory:
40
41:samp:`as`
42 This should be the cross-assembler.
43
44:samp:`ld`
45 This should be the cross-linker.
46
47:samp:`ar`
48 This should be the cross-archiver: a program which can manipulate
49 archive files (linker libraries) in the target machine's format.
50
51:samp:`ranlib`
52 This should be a program to construct a symbol table in an archive file.
53
54The installation of GCC will find these programs in that directory,
55and copy or link them to the proper place to for the cross-compiler to
56find them when run later.
57
58The easiest way to provide these files is to build the Binutils package.
59Configure it with the same :option:`--host` and :option:`--target`
60options that you use for configuring GCC, then build and install
61them. They install their executables automatically into the proper
62directory. Alas, they do not support all the targets that GCC
63supports.
64
65If you are not building a C library in the same source tree as GCC,
66you should also provide the target libraries and headers before
67configuring GCC, specifying the directories with
68:option:`--with-sysroot` or :option:`--with-headers` and
69:option:`--with-libs`. Many targets also require 'start files' such
70as :samp:`crt0.o` and
71:samp:`crtn.o` which are linked into each executable. There may be several
72alternatives for :samp:`crt0.o`, for use with profiling or other
73compilation options. Check your target's definition of
3ed1b4ce 74``STARTFILE_SPEC`` to find out what start files it uses.