]> git.ipfire.org Git - thirdparty/gcc.git/blob - 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
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
6 Building a cross compiler
7 *************************
8
9 When building a cross compiler, it is not generally possible to do a
10 3-stage bootstrap of the compiler. This makes for an interesting problem
11 as parts of GCC can only be built with GCC.
12
13 To build a cross compiler, we recommend first building and installing a
14 native compiler. You can then use the native GCC compiler to build the
15 cross compiler. The installed native compiler needs to be GCC version
16 2.95 or later.
17
18 Assuming you have already installed a native copy of GCC and configured
19 your cross compiler, issue the command :command:`make`, which performs the
20 following 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
33 Note that if an error occurs in any step the make process will exit.
34
35 If you are not building GNU binutils in the same source tree as GCC,
36 you will need a cross-assembler and cross-linker installed before
37 configuring GCC. Put them in the directory
38 :samp:`{prefix}/{target}/bin`. Here is a table of the tools
39 you 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
54 The installation of GCC will find these programs in that directory,
55 and copy or link them to the proper place to for the cross-compiler to
56 find them when run later.
57
58 The easiest way to provide these files is to build the Binutils package.
59 Configure it with the same :option:`--host` and :option:`--target`
60 options that you use for configuring GCC, then build and install
61 them. They install their executables automatically into the proper
62 directory. Alas, they do not support all the targets that GCC
63 supports.
64
65 If you are not building a C library in the same source tree as GCC,
66 you should also provide the target libraries and headers before
67 configuring 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
70 as :samp:`crt0.o` and
71 :samp:`crtn.o` which are linked into each executable. There may be several
72 alternatives for :samp:`crt0.o`, for use with profiling or other
73 compilation options. Check your target's definition of
74 ``STARTFILE_SPEC`` to find out what start files it uses.