Skip to content

Commit 6617236

Browse files
committed
[docs] Change CrossCompilation guidde to reflect changes in Clang/GCC
HowToCrossCompile was outdated and generating too much traffic on the mailing list with similar queries. This change helps offset most of the problems that were reported recently including: * Removing the -ccc-gcc-name, adding --sysroot * Making references to Debian's multiarch for target libraries * Expanding -DCMAKE_CXX_FLAGS for both GCC and Clang * Some formatting and clarifications in the text llvm-svn: 269054
1 parent 14b1cf3 commit 6617236

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

llvm/docs/HowToCrossCompileLLVM.rst

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,38 @@ The CMake options you need to add are:
4646
* ``-DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf``
4747
* ``-DLLVM_TARGET_ARCH=ARM``
4848
* ``-DLLVM_TARGETS_TO_BUILD=ARM``
49-
* ``-DCMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf -mcpu=cortex-a9 -I/usr/arm-linux-gnueabihf/include/c++/4.7.2/arm-linux-gnueabihf/ -I/usr/arm-linux-gnueabihf/include/ -mfloat-abi=hard -ccc-gcc-name arm-linux-gnueabihf-gcc'``
49+
50+
If you're compiling with GCC, you can use architecture options for your target,
51+
and the compiler driver will detect everything that it needs:
52+
* ``-DCMAKE_CXX_FLAGS='-march=armv7-a -mcpu=cortex-a9 -mfloat-abi=hard'``
53+
54+
However, if you're using Clang, the driver might not be up-to-date with your
55+
specific Linux distribution, version or GCC layout, so you'll need to fudge.
56+
57+
In addition to the ones above, you'll also need:
58+
* ``'-target arm-linux-gnueabihf'`` or whatever is the triple of your cross GCC.
59+
* ``'--sysroot=/usr/arm-linux-gnueabihf'``, ``'--sysroot=/opt/gcc/arm-linux-gnueabihf'``
60+
or whatever is the location of your GCC's sysroot (where /lib, /bin etc are).
61+
* Appropriate use of ``-I`` and ``-L``, depending on how the cross GCC is installed,
62+
and where are the libraries and headers.
5063

5164
The TableGen options are required to compile it with the host compiler,
5265
so you'll need to compile LLVM (or at least ``llvm-tblgen``) to your host
53-
platform before you start. The CXX flags define the target, cpu (which
66+
platform before you start. The CXX flags define the target, cpu (which in this case
5467
defaults to ``fpu=VFP3`` with NEON), and forcing the hard-float ABI. If you're
55-
using Clang as a cross-compiler, you will *also* have to set ``-ccc-gcc-name``,
68+
using Clang as a cross-compiler, you will *also* have to set ``--sysroot``
5669
to make sure it picks the correct linker.
5770

71+
When using Clang, it's important that you choose the triple to be *identical*
72+
to the GCC triple and the sysroot. This will make it easier for Clang to
73+
find the correct tools and include headers. But that won't mean all headers and
74+
libraries will be found. You'll still need to use ``-I`` and ``-L`` to locate
75+
those extra ones, depending on your distribution.
76+
5877
Most of the time, what you want is to have a native compiler to the
59-
platform itself, but not others. It might not even be feasible to
60-
produce x86 binaries from ARM targets, so there's no point in compiling
78+
platform itself, but not others. So there's rarely a point in compiling
6179
all back-ends. For that reason, you should also set the
62-
``TARGETS_TO_BUILD`` to only build the ARM back-end.
80+
``TARGETS_TO_BUILD`` to only build the back-end you're targeting to.
6381

6482
You must set the ``CMAKE_INSTALL_PREFIX``, otherwise a ``ninja install``
6583
will copy ARM binaries to your root filesystem, which is not what you
@@ -83,14 +101,23 @@ running CMake:
83101
This is not a problem, since Clang/LLVM libraries are statically
84102
linked anyway, it shouldn't affect much.
85103

86-
#. The ARM libraries won't be installed in your system, and possibly
87-
not easily installable anyway, so you'll have to build/download
88-
them separately. But the CMake prepare step, which checks for
104+
#. The ARM libraries won't be installed in your system.
105+
But the CMake prepare step, which checks for
89106
dependencies, will check the *host* libraries, not the *target*
90-
ones.
107+
ones. Below there's a list of some dependencies, but your project could
108+
have more, or this document could be outdated. You'll see the errors
109+
while linking as an indication of that.
110+
111+
Debian based distros have a way to add ``multiarch``, which adds
112+
a new architecture and allows you to install packages for those
113+
systems. See https://wiki.debian.org/Multiarch/HOWTO for more info.
114+
115+
But not all distros will have that, and possibly not an easy way to
116+
install them in any anyway, so you'll have to build/download
117+
them separately.
91118

92119
A quick way of getting the libraries is to download them from
93-
a distribution repository, like Debian (http://packages.debian.org/wheezy/),
120+
a distribution repository, like Debian (http://packages.debian.org/jessie/),
94121
and download the missing libraries. Note that the ``libXXX``
95122
will have the shared objects (``.so``) and the ``libXXX-dev`` will
96123
give you the headers and the static (``.a``) library. Just in

0 commit comments

Comments
 (0)