Building OF with Clang


I read an interesting article here on Linux development, including some techniques I hadn’t seen before:

Has anyone tried building OF with Clang? Some of the speed improvements might be useful, especially on slower platforms, i.e. SoC systems.


Nice article - I think Clang is used by Xcode on the Mac now so it would seem like a Linux version would be doable.

For SoC (at least on the Raspberry Pi) a cross-compiler/distributed compiler (DISTCC is my fave) is pretty necessary unless you are just building small apps. The linking/ld replacement stuff is especially interesting to me as that part you still have to do on the Pi with a distcc setup. Getting rid of link order hassles? That would be amazing


Probably most of these changes won’t be significant for OF as it’s not a big enough project, but would still be nice to try out. Linking on the desktop seems to have gotten slightly slower on more recent version of OF linux as well.


you can do this per project if you want, in config.make, at the end of the file you can find:


just uncomment them and set them to clang, to set the gold linker just add the linker flags in PROJECT_LD_FLAGS. i think you can also use the gold linker with gcc, at least the android version is using that and yes it’s really much faster.

another optimization is to enable parallel compiling in codeblocks or compile with -j4 or any other value depending on the number of threads you want to use


oF does build with clang on Linux - to quickly investigate, I built oF v0.8.1 three different ways on a Raspberry Pi (Rev 2 Model B, 256/256 memory split, class 10 SD card) running Weezy to get a better idea of compile time. I didn’t vary the linker to check out gold, just the compiler.

Compile Time:

gcc: 62m17.066s
clang: 43m50.706s
distcc / gcc: 6m5.052s

This was quickly calculated with the commands below.


$ gcc --version
gcc (Debian 4.6.3-14+rpi1) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
$ make -C libs/openFrameworksCompiled/project/ clean && time make -s CC=gcc CXX=g++ -C libs/openFrameworksCompiled/project/
real	62m17.066s
user	59m49.970s
sys	1m41.550s


$ clang --version
Debian clang version 3.0-6.2 (tags/RELEASE_30/final) (based on LLVM 3.0)
Target: arm-unknown-linux-gnueabihf
Thread model: posix
$ make -C libs/openFrameworksCompiled/project/ clean && time make -s CC=clang CXX=clang++ -C libs/openFrameworksCompiled/project/
real	43m50.706s
user	42m0.130s
sys	1m15.000s

distcc (gcc)

VM running 32-bit Ubuntu 12.04 with 4 processor cores and 1024 MB of RAM on a 2.8 GHz i7 iMac11,1 (quad-core, 8 with hyperthreading).

$ make -C libs/openFrameworksCompiled/project/ clean && time make -s -j4 CC=/usr/lib/distcc/arm-linux-gnueabihf-gcc CXX=/usr/lib/distcc/arm-linux-gnueabihf-g++ -C libs/openFrameworksCompiled/project/
real	6m5.052s
user	3m47.610s
sys	1m12.770s


Thanks @arturo , I completely forgot about those config.make variables, that makes it super easy. Excellent!

Interesting analysis @pizthewiz, while distcc is obviously faster, looks like there’s a 30% speed up, which would definitely translate to something worthwhile on the desktop, even if it ended up being less


I’d take a 30% speedup any time, even on desktop :smiley:
My quick & dirty analysis on my Ubuntu 13.10 desktop:

$ gcc --version
gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

real    3m39.089s
user    3m11.060s
sys    0m14.392s


$ clang --version
Debian clang version 3.2-7ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
Target: i386-pc-linux-gnu
Thread model: posix

real	2m39.053s
user	2m28.092s
sys	0m6.680s

which comes to 27% savings, not bad.


i want to report that are some weeks that i successfully compile all my projects and addons using clang and gold on debian by simply by editing the /libs/openFrameworksCompiled/project/makefileCommon/ file and adding at the end:

PLATFORM_CXX = clang++ -B/usr/lib/gold-ld


have you heard about this compiler?

it seems to be clang compatible and faster. seems interesting to try with ofw