diff --git a/src/Bin/OpenEnroth/CMakeLists.txt b/src/Bin/OpenEnroth/CMakeLists.txt index e9a7ca6726ac..b86fe90fad84 100644 --- a/src/Bin/OpenEnroth/CMakeLists.txt +++ b/src/Bin/OpenEnroth/CMakeLists.txt @@ -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}) diff --git a/src/Bin/OpenEnroth/libmain.map b/src/Bin/OpenEnroth/libmain.map new file mode 100644 index 000000000000..1b3c234a7187 --- /dev/null +++ b/src/Bin/OpenEnroth/libmain.map @@ -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: *; +}; diff --git a/src/Platform/Sdl/SdlMain.cpp b/src/Platform/Sdl/SdlMain.cpp index 2dfa993e42a9..8c32fcd93798 100644 --- a/src/Platform/Sdl/SdlMain.cpp +++ b/src/Platform/Sdl/SdlMain.cpp @@ -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); }