README.cross 9.44 KB
Newer Older
Tor Lillqvist's avatar
Tor Lillqvist committed
Cross-compiling LibreOffice
Tor Lillqvist's avatar
Tor Lillqvist committed

Cross-compilation works, to various degree, to the following
5 6 7 8
platforms: iOS, Android, and Raspbian.

Note that this document has not been updated very often, and not
everything here necessarily is true any more.
Tor Lillqvist's avatar
Tor Lillqvist committed
9 10 11 12 13 14


In GNU Autoconf terminology, "build" is the platform on which you are
running a build of some software and "host" is the platform on which
Tor Lillqvist's avatar
Tor Lillqvist committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
the software you are building will run. Only in the specific case of
building compilers and other programming tools is the term "target"
used to indicate the platform for which the tools your are building
will produce code. As LibreOffice is not a compiler, the "target" term
should not be used in the context of cross-compilation.

(For a case where all three of "build", "host" and "target" are
different: consider a gcc cross-compiler running on Windows, producing
code for Android, where the cross-compiler itself was built on
Linux. (This is a real case.) An interesting tidbit is that such
configurations are called "Canadian Cross".)

Even though the LibreOffice build mechanism is highly unorthodox, the
configure script takes the normal --build and --host options like any
GNU Autoconf -based configure script. To cross-compile, you basically
need just to specify a suitable --host option and things should work
32 33 34 35 36
out nicely. In practice, many details need to be handled. See examples

Note that in the case of LibreOffice, it is uncommon to run the
configure script directly. Normally one uses the script.
Tor Lillqvist's avatar
Tor Lillqvist committed
The script reads command-line options from file called
autogen.input if it exists. The typical way of working is to keep
Tor Lillqvist's avatar
Tor Lillqvist committed
the configure parameters in that file and edit it as needed.
Tor Lillqvist's avatar
Tor Lillqvist committed
40 41 42 43 44 45

What is so hard, then?

Despite the fact that the configure script takes normal --build and
46 47 48 49 50
--host options, that is just the beginning. It was necessary to
separate tests for "host" and "build" platforms in the configure
script. See the git log for details. And the reasonably "standard" is just the top level; when we get down to the actual
makefilery used to build the bits of LibreOffice, it gets much worse.
Tor Lillqvist's avatar
Tor Lillqvist committed
51 52 53

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

iOS is the operating system on Apple's mobile devices. Clearly for a
device like the iPad it would not be acceptable to run a normal
LibreOffice application with overlapping windows and mouse-oriented
GUI widgets.

It makes sense to use only a part of LibreOffice's code for iOS. Lots
of the GUI-oriented code should be left out. iOS apps that want to use
the applicable LibreOffice code will handle all their GUI in a
platform-dependent manner. How well it will be possible to do such a
split remains to be seen.

Obviously we want it to be possible to eventually distribute apps
using LibreOffice code through the App Store. Technically, one
important special aspect of iOS is that apps in the App Store are not
Tor Lillqvist's avatar
Tor Lillqvist committed
allowed to load own dynamic libraries. (System libraries are used in
the form of dynamic libraries, just like on macOS, of which iOS is
72 73 74
a variant.)

Thus all the libraries in LibreOffice that normally are shared
Tor Lillqvist's avatar
Tor Lillqvist committed
libraries (DLLs on Windows, shared objects (.so) on Linux, dynamic
libraries on macOS (.dylib)) must be built as static archives
77 78 79
instead. This has some interesting consequences for how UNO is
implemented and used.

Andrea Gelmini's avatar
Andrea Gelmini committed
80 81
An iOS app is a "bundle" that contains a single executable. In an app
using LibreOffice code, that executable then contains the necessary
82 83 84 85 86 87 88
LibreOffice libraries and UNO components statically linked.

The Apple tool-chain for iOS cross-building is available only for OS
X. In order to be able to run and debug an app on an actual device
(and not just the iOS Simulator) you need to be registered in the iOS
Developer Program.

Here is an autogen.input for iOS (device) using Xcode 4.6, on macOS 10.8:

Tor Lillqvist's avatar
Tor Lillqvist committed
91 92
93 94 95
Tor Lillqvist's avatar
Tor Lillqvist committed

97 98
For the iOS Simulator, but note that building for the simulator is
broken at the moment (July 2014):

Tor Lillqvist's avatar
Tor Lillqvist committed
100 101 102
103 104
105 106

107 108 109
You will have to install autoconf and automake yourself before running They are no longer included in Xcode 4.3 and later (not
even in the add-on "command line tools").

The -mmacosx-version-min=10.7 is necessary when building for the iOS
112 113 114
simulator to avoid clang replacing simple calls to fprintf with calls
to fwrite$UNIX2003 which Xcode then warns that doesn't exist on iOS.


Tor Lillqvist's avatar
Tor Lillqvist committed
Tor Lillqvist's avatar
Tor Lillqvist committed

119 120 121 122 123 124 125
From a technical point of view the core Android OS (the kernel) is
Linux, but everything else is different. Unlike iOS, an Android app
can use shared objects just fine, so that aspect of UNO doesn't need
special handling. Except that there is a silly low limit in the
Android dynamic linker on the number of libraries you can dlopen. This
is a limitation in user-level (but system-provided and not really
replaceable) code, not the kernel.
Tor Lillqvist's avatar
Tor Lillqvist committed

127 128 129 130
Thus, just like for iOS, also for Android the LibreOffice libraries
and UNO components are built as static archives. For Android, those
static archives, and any app-specific native code, are linked into one
single app-specific shared library, called
Tor Lillqvist's avatar
Tor Lillqvist committed

132 133
For the GUI, the same holds as said above for iOS. The GUI layer needs
to be platform-specific, written in Java.
Tor Lillqvist's avatar
Tor Lillqvist committed

Android cross-compilation work has been done mainly on Linux (openSUSE
in particular). Earlier also cross-compiling from macOS was tried. The
Android cross-compilation tool-chain (the "Native Development Kit", or
NDK) is available for Linux, macOS and Windows, but trying to
cross-compile LibreOffice from Windows will probably drive you insane.
Tor Lillqvist's avatar
Tor Lillqvist committed

141 142
You will also need the Android SDK as full "make" also builds a couple
of Android apps where the upper layer is written in Java.

Use the "android" tool from the SDK to install the SDK Tools, SDK
Platform Tools, the API 15 SDK Platform and the Android Support
146 147
Library. If you want to run the Android apps in the emulator, you of
course need an appropriate system image for that.

Tor Lillqvist's avatar
Tor Lillqvist committed
Here is an autogen.input for Android on ARM when cross-compiling
from Linux:

152 153 154

Tor Lillqvist's avatar
Tor Lillqvist committed
And here is an (quite old) autogen.input for Android on X86:
157 158 159 160 161 162 163

Tor Lillqvist's avatar
Tor Lillqvist committed

A LibreOffice app for Android is being developed progress in the
android/source directory.
167 168

To run the app, do "make install" followed by either "make run" or
169 170
starting it from Android itself. You most likely want to have an "adb logcat"
running in another window. To debug, run "make debugrun".

172 173 174 175
NB: If you happen to upgrade to Android SDK Tools 23, and the build (using
'make verbose=t android') fails for you with:

       [dx] /local/libreoffice/android-sdk-linux/tools/support/annotations.jar (no such file or directory)
177 178 179 180 181 182

you need to copy the annotations.jar from an older sdk; like

wget ''
cp tools/support/annotations.jar <android-sdk-linux>/tools/support/
Tor Lillqvist's avatar
Tor Lillqvist committed


In theory, this should work also for another Linux, it does not need to be Raspbian.
But this cross-compilation work is tested from Debian and openSUSE to Raspbian.

190 191
You will need headers, pkg-config files and libraries from a Raspbian
system to build against. Available at
192 . Look for the latest
193 194
raspbian-root-*.tar.gz . For instance:

$ wget
196 197 198
$ mkdir raspbian-root
$ cd raspbian-root
$ tar -xf raspbian-root-20140120.tar.gz
199 200 201

You can build cross-compiler yourself or get the executables here:
$ git clone git://

203 204 205 206 207 208
tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian is known to work.

Then create pkg-config wrapper, something like:
$ cat > pkg-config-wrapper-host << _EOF

if [ "$CROSS_COMPILING" = TRUE ]; then
210 211 212 213 214
   export PKG_CONFIG_PATH=${SYSROOT}/usr/lib/arm-linux-gnueabihf/pkgconfig:${SYSROOT}/usr/share/pkgconfig
   export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig
215 216 217 218

exec pkg-config "\$@"
$ chmod +x pkg-config-wrapper-host

220 221
This does not work with pkg-config 0.23. 0.26 is known to work.

Tor Lillqvist's avatar
Tor Lillqvist committed
And you are ready to build with autogen.input similar to:
223 224 225 226 227 228

CC=<path-to-arm-linux-gnueabihf-gcc> --sysroot=<path-to-raspbian_rootfs>
CXX=<path-to-arm-linux-gnueabihf-g++> --sysroot=<path-to-raspbian_rootfs>
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244

Finally, when you are ready to run the binaries in Raspbian,
245 246 247 248
you may need to get more system libraries, who knows.
$ sudo apt-get install libreoffice # or similar
That installs libreoffice too, which you don't need because you have
just built one, but I don't know how to avoid it easily.