Compiling with Clang instead of gcc

From Elite Wiki
Revision as of 21:34, 3 August 2025 by Mcarans (talk | contribs) (-fobjc-runtime=gnustep-1.9 is now in Gnumakefile)

This article describes how to build Oolite from source using Clang instead of gcc.

Open a shell. To force building with Clang for all subsequent commands in your shell, you need to create environment variables for CC and CXX that point to clang. For Linux, it is like this:

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++

Then build the latest release of libobjc2 (2.2.1 at time of writing) from source as described here.

Then build the latest release of gnustep-base (1.31.1 at time of writing) from source as described here.

A compiler flag required when building Oolite with Clang is directly in Oolite's GNUmakefile (and so doesn't need to be added manually as used to be necessary). You can see the flag if you open a text editor and load GNUmakefile. There is a line that looks like this:

ADDITIONAL_OBJCFLAGS += -fobjc-runtime=gnustep-1.9

Now you can build Oolite in the usual way eg. for Linux:

source /usr/share/GNUstep/Makefiles/GNUstep.sh
make -f Makefile release-deployment -j$(nproc)

You can force the use of the Clang/LLVM linker ldd instead of GNU's ld by adding this line to GNUmakefile next to the line with -fobjc-runtime=gnustep-1.9 in it:

ADDITIONAL_LDFLAGS += -fuse-ld=lld

However, it gave a segmentation fault for me which means that rather strangely, I must use GNU's linker ld for linking when compiling with Clang.


The -fobjc-runtime flag is described as follows here:

The GNUstep Objective-C runtime was designed as a drop-in replacement for the GCC runtime. It supports three ABIs:

  • The old GCC ABI, which provides support for Objective-C 1.0 features. This can be selected via the -fobjc-runtime=gcc flag in Clang or by compiling with GCC.
  • The initial GNUstep non-fragile ABI, which was intended to be compatible with the GCC ABI, but provide support for modern Objective-C features. This can be selected with the -fobjc-runtime=gnustep-1.9 flag in Clang.
  • The modern (v2) ABI, which provides richer reflection metadata, smaller binaries and reduced memory usage. This is selected with the -fobjc-runtime=gnustep-2.0 flag in Clang 7.0 or later.