Difference between revisions of "Compiling with Clang instead of gcc"

From Elite Wiki
m
m
Line 6: Line 6:
 
  export CXX=/usr/bin/clang++
 
  export CXX=/usr/bin/clang++
  
Then build the latest release of libobjc2 ([https://github.com/gnustep/libobjc2/releases/tag/v2.2.1 2.2.1] at time of writing) from source as described [https://github.com/gnustep/libobjc2/blob/master/INSTALL here].
+
Then build the latest release of ''libobjc2'' ([https://github.com/gnustep/libobjc2/releases/tag/v2.2.1 2.2.1] at time of writing) from source as described [https://github.com/gnustep/libobjc2/blob/master/INSTALL here].
  
Then build the latest release of gnustep-base ([https://github.com/gnustep/libs-base/releases/tag/base-1_31_1 1.31.1] at time of writing) from source as described [https://github.com/gnustep/libs-base/blob/master/INSTALL here].
+
Then build the latest release of ''gnustep-base'' ([https://github.com/gnustep/libs-base/releases/tag/base-1_31_1 1.31.1] at time of writing) from source as described [https://github.com/gnustep/libs-base/blob/master/INSTALL here].
  
 
Open a text editor and load Oolite's ''GNUmakefile''. Look for the line:
 
Open a text editor and load Oolite's ''GNUmakefile''. Look for the line:

Revision as of 06:02, 23 July 2025

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.

Open a text editor and load Oolite's GNUmakefile. Look for the line:

OBJC_PROGRAM_NAME = oolite:

Above this line put:

ADDITIONAL_OBJCFLAGS += -fobjc-runtime=gnustep-1.9

Save the file.

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:

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.