SDL: macOS: 'SDL2/SDL_main.h' file not found
Hi, I’m updating the dependencies of Unvanquished and tried to update from SDL 2.0.12 to 2.26.5.
The macOS CI runner reported me that build error:
In file included from /Users/runner/work/1/s/src/engine/client/cl_main.cpp:59:
/Users/runner/work/1/s/external_deps/macos-amd64-default_9/SDL2.framework/Headers/SDL.h:32:10: fatal error: 'SDL2/SDL_main.h' file not found
#include <SDL2/SDL_main.h>
^~~~~~~~~~~~~~~~~
1 error generated.
We use SDL2.framework files from the SDL2 dmg (SDL2-2.0.12.dmg or SDL2-2.26.5.dmg).
I noticed this change:
$ grep 'SDL_main.h' macos-amd64-default_8/SDL2.framework/Versions/A/Headers/SDL.h
#include "SDL_main.h"
$ grep 'SDL_main.h' macos-amd64-default_9/SDL2.framework/Versions/A/Headers/SDL.h
#include <SDL2/SDL_main.h>
It happens that the Headers/ folder in macOS SDL2.framework doesn’t contain any SDL2 folder so the SDL2/ prefix in the include lines break the includes.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (4 by maintainers)
The
SDL2::SDL2target will only link to the SDL2 library, not to SDL2_main. This is not done automatically because your project might useSDL_MAIN_HANDLEDto avoid renaming ofmaintoSDL_main.Because yours does not, you need to add
SDL2::SDL2mainbeforeSDL2::SDL2. The following will work on all platforms that provide SDL2_main, or not.OK, I got the game engine building and linking against SDL2 on both macOS and Linux by doing that: