libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.75k stars 1.81k forks source link

SDL3: Rename library includes on macos or change folder structure -> by default includes have wrong naming #11091

Open mo-db opened 1 week ago

mo-db commented 1 week ago

SDL3.1.3: The header files are included with <SDL3/SDL...>. But when installing like mentioned in the macos install readme under Frameworks I (think) i need to include them like this: "-I/Library/Frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework/headers" while compiling and #include in the file

This then doesn't work because all the other files include SDL with <SDL3/SDL...> so to make it work i need to either change all those includes in the header files or change the folder structure to /headers/SDL3/SDL...

slouken commented 1 week ago

If you have the framework in your path, you don't need to add any include statements at all. Xcode will automatically pick up the include path from the framework, like other system frameworks.

madebr commented 1 week ago

Using the xcfamework with CMake and xcode should work out-of-the box.

When trying to build an application from the terminal using a makefile, I had to look at the xcframework release tests (this is hidden by CMake abstractions). These commands were run to build a test application:

/Applications/Xcode_15.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -iframework /Volumes/SDL3/SDL3.xcframework/macos-arm64_x86_64 -arch arm64 -arch x86_64 -isysroot /Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -F /Volumes/SDL3/SDL3.xcframework/macos-arm64_x86_64 -MD -MT CMakeFiles/gui-whatever.dir/main_gui.c.o -MF CMakeFiles/gui-whatever.dir/main_gui.c.o.d -o CMakeFiles/gui-whatever.dir/main_gui.c.o -c /tmp/tardir/SDL3-3.1.3/cmake/test/main_gui.c
/Applications/Xcode_15.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -arch arm64 -arch x86_64 -isysroot /Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Wl,-headerpad_max_install_names "CMakeFiles/gui-whatever.dir/main_gui.c.o" -o gui-whatever -F/Volumes/SDL3/SDL3.xcframework/macos-arm64_x86_64  -framework SDL3

So this is what you need to add:

Replace /Volumes/SDL3 with the location where you extracted the dmg.

mo-db commented 1 week ago

Thx for the answers, i don't use xcode. I just work with makefiles and nvim. I installed SDL here: /Library/Frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework

Also I have to say that I'm relatively new to the macos environment for programming. Normally i just add the flags to my Makefile, generate a compile_commands.json with bear - so that the clang lsp in nvim finds my includes, and then build (i did it that way with SDL2). Tried that in my Makefile:

# MAKEFILE
SDL3_CFLAGS := -I/Library/Frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework/Headers
SDL3_LD := -F/Library/Frameworks -framework SDL3

CFLAGS := -Wall -g -MMD -MP $(SDL3_CFLAGS)
LDFLAGS := $(SDL3_LD)

This didn't work because of the include naming. So i just added the SDL3 folder after the Headers folder. Now when inside nvim i get linting and clang finds everything but i get this error in nvim: Unknown argument: '-framework SDL3' [drv_unknown_argument] And also while compiling SDL3 framework isn't found.

So thx for the cmake flags. With those i can compile and also in nvim i find everything after creating the compile_commands.json with bear.

# MAKEFILE
SDL3_CFLAGS := -iframework /Volumes/SDL3/SDL3.xcframework/macos-arm64_x86_64 -F /Volumes/SDL3/SDL3.xcframework/macos-arm64_x86_64
SDL3_LD := -F /Volumes/SDL3/SDL3.xcframework/macos-arm64_x86_64 -framework SDL3

CFLAGS := -Wall -g -MMD -MP $(SDL3_CFLAGS)
LDFLAGS := $(SDL3_LD)

But now if i try to run one example program from this repo (renderer/03-lines). I get this error:

dyld[64807]: Library not loaded: @rpath/SDL3.framework/Versions/A/SDL3
  Referenced from: <6523BEFC-8D0F-324C-80AE-4FC2B8224BBC> /Users/moritz/Repos/SDL3_PROJS/software_renderer_01/bin/a.out
  Reason: no LC_RPATH's found
fish: Job 1, './bin/a.out' terminated by signal SIGABRT (Abort)

Any idea? All input welcome and thx for responding.

madebr commented 1 week ago

The error looks rpath related.

I'd suggest to create a little SDL3 cmake project using the xcframework, configure with the Unix Makefiles of Ninja generator, and build in verbose mode. Then copy compile and link arguments to your makefile until you get it working. And don't forget to tell us what worked and didn't work :)