Building a GDExtension for Windows and Linux on a Mac?

Godot Version

v4.2.2.stable.official [15073afe3]

Question

I’m working on my first GDExtension, the porting of a GDScript game component to C++.

I’m using a Mac with macOS 14.5, but I’d like to target Windows, Linux, Mac and Android (and later, perhaps, iOS).

The rewritten component is working properly in my Godot project, and I can build the extension for the Mac and for Android. (I have only tested the gdextension version of my game on the Mac, and the performance gain is enormous. I haven’t yet tested the gdextension on Android, but the build process for it reports no problems, and the .so files are present after the build completes.)

I’m having trouble building for Windows and Linux, however.

These are the scons commands I’ve been trying:

scons platform=windows bits=64

scons: Reading SConscript files ...
WARNING: Unknown SCons variables were passed and will be ignored:
    bits=64
Auto-detected 8 CPU cores available for build parallelism. Using 7 cores by default. You can override it with the -j argument.
Building for architecture arm64 on platform windows
scons: done reading SConscript files.
scons: Building targets ...
Compiling godot-cpp/src/godot.cpp ...
sh: arm64-w64-mingw32-g++: command not found
Compiling godot-cpp/src/classes/wrapped.cpp ...
sh: arm64-w64-mingw32-g++: command not found
Compiling godot-cpp/src/classes/low_level.cpp ...
scons: *** [godot-cpp/src/godot.windows.template_debug.arm64.o] Error 127
sh: arm64-w64-mingw32-g++: command not found
scons: *** [godot-cpp/src/classes/wrapped.windows.template_debug.arm64.o] Error 127
scons: *** [godot-cpp/src/classes/low_level.windows.template_debug.arm64.o] Error 127
scons: building terminated because of errors.

(Interestingly, the warning regarding “bits=64” being an unknown SCons variable doesn’t seem to be accurate, as this is definitely not ignored, and omitting it would result in file names with 32 instead of 64 in them.)

scons platform=linux bits=64

scons: Reading SConscript files ...
WARNING: Unknown SCons variables were passed and will be ignored:
    bits=64
Auto-detected 8 CPU cores available for build parallelism. Using 7 cores by default. You can override it with the -j argument.
Building for architecture arm64 on platform linux
scons: done reading SConscript files.
scons: Building targets ...
Compiling godot-cpp/src/godot.cpp ...
Compiling godot-cpp/src/classes/wrapped.cpp ...
Compiling godot-cpp/src/classes/low_level.cpp ...
Compiling godot-cpp/src/classes/editor_plugin_registration.cpp ...
Compiling godot-cpp/src/core/memory.cpp ...
Compiling godot-cpp/src/core/method_bind.cpp ...
clang: error: unknown argument: '-fno-gnu-unique'
clang: error: unknown argument: '-fno-gnu-unique'
Compiling godot-cpp/src/core/class_db.cpp ...
scons: *** [godot-cpp/src/godot.linux.template_debug.arm64.o] Error 1
scons: *** [godot-cpp/src/classes/wrapped.linux.template_debug.arm64.o] Error 1
clang: error: unknown argument: '-fno-gnu-unique'
clang: error: unknown argument: '-fno-gnu-unique'
scons: *** [godot-cpp/src/classes/low_level.linux.template_debug.arm64.o] Error 1
scons: *** [godot-cpp/src/classes/editor_plugin_registration.linux.template_debug.arm64.o] Error 1
clang: error: unknown argument: '-fno-gnu-unique'
scons: *** [godot-cpp/src/core/memory.linux.template_debug.arm64.o] Error 1
clang: error: unknown argument: '-fno-gnu-unique'
scons: *** [godot-cpp/src/core/method_bind.linux.template_debug.arm64.o] Error 1
clang: error: unknown argument: '-fno-gnu-unique'
scons: *** [godot-cpp/src/core/class_db.linux.template_debug.arm64.o] Error 1
scons: building terminated because of errors.

What could be wrong here and how should I fix the problem?

I’m hoping that it’s just an oversight on my end, as the entire concept of GDExtensions and C++ put together is quite a mouthful (brainful?) for me.

Looks like you will also need to include arch=x86_64 since your mac is an arm chip and most windows machines are x86.

For windows it’s trying to compile with arm64-w64-mingw32-g++ which you do not have installed, and that arch parameter should be set to change it to x86_64-w64-mingw32-g++, which you might also not have installed.

For linux it’s trying to use clang, I believe the option “-fno-gnu-unique” helps to disable more parts of the standard library but my version 18.1.8, doesn’t have it either. It may go away with the arch parameter. Again most linux gamers will be on x86.

1 Like

Thank you for these suggestions!

Using the arch_x86_64 scons flag and installing mingw-w64 (via brew install mingw-w64) has indeed solved the problem with the Windows compilation. :slight_smile:

Unfortunately, Linux is still resisting. I’ve tried to install “llvm” (via brew install llvm) and also “gcc” (via brew install gcc) but clang is very insistent on handling the work for Linux. The Microsoft “AI” has suggested various ways of telling scons to use gcc instead of clang, but even after determining that the Homebrew version of gcc is actually called “gcc-14” and specifying these in the build command with scons platform=linux arch=x86_64 bits=64 CC=gcc-14 CXX=g++-14 has made exactly no difference. :frowning:

❯ scons platform=linux arch=x86_64 bits=64 CC=gcc-14 CXX=g++-14
scons: Reading SConscript files ...
WARNING: Unknown SCons variables were passed and will be ignored:
    bits=64
    CC=gcc-14
    CXX=g++-14
Auto-detected 8 CPU cores available for build parallelism. Using 7 cores by default. You can override it with the -j argument.
Building for architecture x86_64 on platform linux
scons: done reading SConscript files.
scons: Building targets ...
Compiling godot-cpp/src/godot.cpp ...
Compiling godot-cpp/src/classes/wrapped.cpp ...
Compiling godot-cpp/src/classes/low_level.cpp ...
Compiling godot-cpp/src/classes/editor_plugin_registration.cpp ...
Compiling godot-cpp/src/core/memory.cpp ...
clang: error: unknown argument: '-fno-gnu-unique'
clang: error: unsupported argument 'x86-64' to option '-march='
Compiling godot-cpp/src/core/method_bind.cpp ...
clang: error: unknown argument: '-fno-gnu-unique'
clang: error: unsupported argument 'x86-64' to option '-march='
scons: *** [godot-cpp/src/godot.linux.template_debug.x86_64.o] Error 1
clang: error: unknown argument: '-fno-gnu-unique'
clang: error: unsupported argument 'x86-64' to option '-march='
scons: *** [godot-cpp/src/classes/wrapped.linux.template_debug.x86_64.o] Error 1
scons: *** [godot-cpp/src/classes/low_level.linux.template_debug.x86_64.o] Error 1
clang: error: unknown argument: '-fno-gnu-unique'
clang: error: unsupported argument 'x86-64' to option '-march='
scons: *** [godot-cpp/src/classes/editor_plugin_registration.linux.template_debug.x86_64.o] Error 1
clang: error: unknown argument: '-fno-gnu-unique'
clang: error: unsupported argument 'x86-64' to option '-march='
scons: *** [godot-cpp/src/core/memory.linux.template_debug.x86_64.o] Error 1
clang: error: unknown argument: '-fno-gnu-unique'
clang: error: unsupported argument 'x86-64' to option '-march='
scons: *** [godot-cpp/src/core/method_bind.linux.template_debug.x86_64.o] Error 1
scons: building terminated because of errors.

(When I don’t specify the CC and CXX flags, the errors are the same, except for there are no warnings regarding these flags.)

I’m somewhat surprised by the 'x86-64' to option '-march=' in the error messages, as I have not used a hyphen anywere in the scons commands, but I also haven’t used ‘-march’ (but arch=x86_64) so that might be coming from somewhere else.

According to the Microsoft AI I’m obviously trying to do cross development (on Mac for Linux), for which I should install “GNU Binutils” with brew install x86_64-linux-gnu-binutils, but (the AI continues) I might even need a “complete cross-compiler toolchain” and for this I should execute brew tap messense/macos-cross-toolchains and brew install x86_64-unknown-linux-gnu.

As I’m sure it’s perfectly clear, I have no idea what I’m doing, so I’m reluctant to obey the AI as it’d surely have me download the entire internet before admitting that it’s hallucinating again. Or this time its tips are correct?

Could it be

CC=gcc-14 CXX=g++-14 scons platform=linux arch=x86_64 bits=64 

Usually CC and CXX are environment variables, especially for makefiles, but I am not familiar with scons

1 Like

I’ve tried to specify CC and CXX as env variables, even exported them from my ~/.zprofile and made sure echo $CC and echo $CXX are printing what they should, but scons just doesn’t care, it’s only talking to ‘clang’, which keeps complaining.

Very sad, CC and CXX are options when building the Godot engine source, but the c++ template seems lacking, and mine must have broken with a system update >:(

You can check for more options with scons -h, maybe use less to help read through and search scons -h | less

1 Like

C++14 may not be appropriate, as the code base uses c++17 features like constexp and attributes like fallathrough

1 Like

I’m not sure if the gcc I’ve installed through Homebrew was ever used by scons, as the error messages all came from clang, which – as I currently believe – is provided by Apple.

According to this StackOverflow response, C++17 has to be explicitly activated (e.g. g++ --std=c++17 <filename>.cpp). Microsoft AI has recommended adding this to my SConstruct for this purpose: env.Append(CXXFLAGS=['-std=c++17']), but I still see the exact same error messages.

At this point I think I should try to build my gdextension on a native Linux (for the Linux version) and see if it’s working.

Indeed, on Linux Mint the build process for Linux has completed, and the built .so file is working as expected in the game.

Perhaps I should post this thread to the official Godot github issues page, as I’m still unable to build the Linux version on a Mac while the other platforms do work. Perhaps the GDextension documentation should mention this or offer steps for a resolution.

1 Like