Development/Building LibreOffice with Clang

Mac works with clang by default.

On Linux systems add the following to your autogen.input: CC=clang CXX=clang++

ccache users will need to set the following e.g. in ~/.bashrc (ccache is used automatically assuming it is installed and configured correctly) -- autogen will warn you if this isn't set. export CCACHE_CPP2=1

You should also install the clang headers (clang-devel or your distro's equivalent) for the clang loplugin to build. Autogen will warn you if these are missing.

For example on Debian, install these packages:
 * 'clang' for main clang programs
 * 'libclang- -dev' (number corresponding to clang version installed) for clang headers
 * 'llvm' mandatory to build compiler-plugins, if not you'll have error message 'Cannot find Clang headers to build compiler plugins'

openSuse 12.3 is known to work without any further setup (assuming you have all official updates), read the rest of this page to ensure you have the correct dependencies when working with other linux systems.

Building LibreOffice with Clang
It is possible to build LibreOffice using the Clang compiler instead of the GCC compiler.

Bootstraping clang on Linux
See this article how to build clang on linux: https://btorpey.github.io/blog/2015/01/02/building-clang/

Using libc++/libc++abi with clang on Linux
Building LO against libc++ with  is know to work from 5.2 on. The previous issues were resolved in https://bugs.documentfoundation.org/show_bug.cgi?id=97712

Setup
Use
 * LibreOffice - Version 3.6 has been tested to build and work without problems on Linux. See below for macOS details. Older LibreOffice versions may or may not build and work.
 * Clang - version 3.1+ works. Older versions may not work.
 * Some libraries may need to be upgraded, mostly because of Clang's stricter/earlier implementation of C++11.
 * Libstdc++ 4.6 is known to work. Other libstdc++ versions may need patching (see Clang C++11 status page for information and patches).
 * Boost 1.47 and older may need patching (see this page). Internal copy of Boost shipped with LibreOffice builds fine.
 * NSS may need a patch or upgrade. Internal copy of NSS shipped with LibreOffice builds fine.
 * Qt4 may need a patch or upgrade. See Qt bugreport for a patch.
 * Ccache works. At least version 3.1.10 (not yet released as of January 8th 2013) is needed when using compiler plugins (--enable-dbgutil or --enable-compiler-plugins), 3.1.9 needs a patch, older versions need also another patch). Older versions (version 3.1.7, possibly older) work when not using plugins.

export CCACHE_CPP2=1

otherwise Clang will report preprocessed sources in error messages, print some warnings in header files it wouldn't print otherwise, and print warnings about unused options -D and -I.
 * Icecream needs to be at least version 1.0
 * On recent Fedora 17, the included Clang (3.0) is unusable due to clang++ chokes on. However, a home-built Clang 3.1 works fine.

Building
Configuring LibreOffice is done normally, except that Clang is used as the compiler:

$ ./autogen.sh CC=clang CXX=clang++ ... plus the usual configure options, see Development/BuildingOnLinux

Otherwise the build should work just like when building with GCC.

If you have done previous builds with gcc, sometimes it's necessary to run:

$ make distclean

Problems
Although Clang can be mostly used as a drop-in replacement for GCC, it is an entirely different compiler, so there may be Clang-specific problems. In general it is however normally usable.

There should be also a tinderbox using Clang as the compiler, so if there is a problem, it might be useful to check its status.

Setup
XCode 4 has been installed on the machine and using gcc-4.2 (non-LLVM) the configuration will do a successfull LibreOffice build, which will also launch correctly. Make sure any 64-bit binaries in the PATH (e.g. pkg-config) are hidden. If you happen to have the Mono Framework installed, hide /usr/bin/pkg-config.

For the clang build, the following worked:

CC="clang -m32" CXX="clang++ -m32" ./autogen.sh --with-num-cpus=8 --with-max-jobs=8 --prefix=/source/libo/prefix --with-macOS-sdk=10.6 --with-macOS-version-max-allowed=10.6 --with-macOS-version-min-required=10.5 --disable-mozilla --without-help --without-doxygen --without-myspell-dicts

Example setup
One scenario that at least works for me (Stephan Bergmann) is the below script, slightly updated from &ldquo;Building on macOS 10.7&rdquo;: