Difference between revisions of "Compiling with Clang instead of gcc"
m |
(-fobjc-runtime=gnustep-1.9 is now in Gnumakefile) |
||
| Line 10: | Line 10: | ||
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]. | ||
| − | + | 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 | ADDITIONAL_OBJCFLAGS += -fobjc-runtime=gnustep-1.9 | ||
| − | |||
| − | |||
Now you can build Oolite in the usual way eg. for Linux: | Now you can build Oolite in the usual way eg. for Linux: | ||
| Line 25: | Line 19: | ||
make -f Makefile release-deployment -j$(nproc) | 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'': | + | 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 <code>-fobjc-runtime=gnustep-1.9</code> in it: |
ADDITIONAL_LDFLAGS += -fuse-ld=lld | ADDITIONAL_LDFLAGS += -fuse-ld=lld | ||
Revision as of 21:34, 3 August 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.
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=gccflag 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.9flag 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.0flag in Clang 7.0 or later.