Skip to content

Commit

Permalink
See if we can export SDL_main on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Sep 19, 2023
1 parent 8fc1400 commit 96a7822
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Bin/OpenEnroth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if(BUILD_PLATFORM STREQUAL "android")
target_sources(main PUBLIC ${BIN_OPENENROTH_HEADERS} ${BIN_OPENENROTH_SOURCES})
target_check_style(main)
target_link_libraries(main PUBLIC application CLI11::CLI11)
target_link_options(main PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libmain.map")
else()
add_executable(OpenEnroth MACOSX_BUNDLE)
target_sources(OpenEnroth PUBLIC ${BIN_OPENENROTH_HEADERS} ${BIN_OPENENROTH_SOURCES})
Expand Down
6 changes: 6 additions & 0 deletions src/Bin/OpenEnroth/libmain.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Linker script used when linking libmain.so for Android.
* Note that SDL_main is declared in SdlMain.cpp. */
{
global: SDL_main;
local: *;
};
5 changes: 3 additions & 2 deletions src/Platform/Sdl/SdlMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

int platformMain(int argc, char **argv);

// This gets #defined by SDL into SDL_main.
int main(int argc, char **argv) {
// This gets #defined by SDL into SDL_main. Marking it as extern "C" is important for name mangling as on Android
// it gets exported from the resulting .so.
extern "C" int main(int argc, char **argv) {
return platformMain(argc, argv);
}

0 comments on commit 96a7822

Please sign in to comment.