Difference between revisions of "Compiling with Clang instead of gcc"
(Clarification) |
Cholmondely (talk | contribs) (Added another link) |
||
| (7 intermediate revisions by 2 users not shown) | |||
| Line 60: | Line 60: | ||
* The modern (v2) ABI, which provides richer reflection metadata, smaller binaries and reduced memory usage. This is selected with the <code>-fobjc-runtime=gnustep-2.0</code> flag in Clang 7.0 or later. | * The modern (v2) ABI, which provides richer reflection metadata, smaller binaries and reduced memory usage. This is selected with the <code>-fobjc-runtime=gnustep-2.0</code> flag in Clang 7.0 or later. | ||
| − | Note that currently there is a [https://github.com/gnustep/libobjc2/issues/357 linking error] when trying to build Oolite using the supported ABI 2.2. On Windows MinGW64, there are unfortunately issues that prevent building GNUStep Base with ABI 1.9. ABI 1.9 | + | Note that currently there is a [https://github.com/gnustep/libobjc2/issues/357 linking error] when trying to build Oolite using the supported ABI 2.2. On Windows MinGW64, there are unfortunately issues that prevent building GNUStep Base with ABI 1.9. Curiously, compiling with the following (still using Clang) but leaving the ABI as 1.9 in Oolite's GNUmakefile also worked: |
| + | |||
| + | ./configure --prefix=/usr --with-library-combo=gnu-gnu-gnu --with-libdir=lib --with-objc-lib-flag="-L/usr/lib/x86_64-linux-gnu/ -lobjc" | ||
| + | |||
| + | Clang ABI 1.9 only works with Oolite on Linux not MinGW64. ABI 1.9 is unsupported so GNUStep developers do not offer assistance or bug fixes for it. Hence even if it were possible to get it to work on all platforms, it would probably be inadvisable to switch Oolite to use Clang ABI 1.9. | ||
| + | |||
| + | == Links == | ||
| + | *[https://bb.oolite.space/viewtopic.php?t=21973 Success Clang ABI 2.2!] (2025) | ||
| + | *[https://bb.oolite.space/viewtopic.php?t=21898 BB thread: Clang build ABI 1.9 Linux only (+latest gnustep-base) (solved)] (2025) | ||
| + | |||
| + | |||
| + | [[Category:Oolite Development]] | ||
Latest revision as of 10:43, 4 November 2025
This article describes how to build Oolite from source using Clang instead of gcc on Linux.
The following lines must be run inside a shell. They are set up for Ubuntu flavours, but can be adapted for other Linux distributions.
export CC=/usr/bin/clang export CXX=/usr/bin/clang++
cd libobjc2 rm -rf build mkdir build cd build cmake -DTESTS=on -DCMAKE_BUILD_TYPE=Release -DGNUSTEP_INSTALL_TYPE=NONE -DCMAKE_INSTALL_PREFIX=/usr -DEMBEDDED_BLOCKS_RUNTIME=ON -DOLDABI_COMPAT=ON ../ cmake --build . sudo cmake --install . cd ../..
cd tools-make ./configure --prefix=/usr --with-library-combo=ng-gnu-gnu --with-libdir=lib --with-runtime-abi=gnustep-1.9 --with-objc-lib-flag="-L/usr/lib/x86_64-linux-gnu/ -lobjc" make sudo make install cd ..
cd libs-base . /usr/share/GNUstep/Makefiles/GNUstep.sh ./configure --prefix=/usr make -j16 sudo make install cd ..
The export lines force building with Clang for all subsequent commands by creating environment variables for CC and CXX that point to clang.
It is assumed that the latest release of libobjc2 (2.2.1 at time of writing) is in the folder libobjc2. More on building the package from source here.
It is assumed that the latest release of gnustep-make (2.9.3 at time of writing) is in the folder tools-make. More on building the package from source here.
It is assumed that the latest release of gnustep-base (1.31.1 at time of writing) is in the folder libs-base. More on building the package from source 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 was previously needed). 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.
Note that currently there is a linking error when trying to build Oolite using the supported ABI 2.2. On Windows MinGW64, there are unfortunately issues that prevent building GNUStep Base with ABI 1.9. Curiously, compiling with the following (still using Clang) but leaving the ABI as 1.9 in Oolite's GNUmakefile also worked:
./configure --prefix=/usr --with-library-combo=gnu-gnu-gnu --with-libdir=lib --with-objc-lib-flag="-L/usr/lib/x86_64-linux-gnu/ -lobjc"
Clang ABI 1.9 only works with Oolite on Linux not MinGW64. ABI 1.9 is unsupported so GNUStep developers do not offer assistance or bug fixes for it. Hence even if it were possible to get it to work on all platforms, it would probably be inadvisable to switch Oolite to use Clang ABI 1.9.