diff --git a/src/core.h b/src/core.h index b0a8e522..834dfe7b 100644 --- a/src/core.h +++ b/src/core.h @@ -69,12 +69,27 @@ static inline int isnan(float f) #endif /* If using SDL, let it override main() but immediately replace - * the override with ours. */ + * the override with ours, then declare weak symbols to ensure one + * of our dummy functions gets replaced by the user's main(). */ #if defined USE_SDL # include # if defined main && !LOL_DONT_DIVERT_MAIN # undef main # define main lol_sdl_main +# if defined _MSC_VER +int lol_sdl_main(); +int lol_sdl_main_msvc(); +#pragma comment(linker, "/alternatename:?lol_sdl_main@@YAHXZ" \ + "=?lol_sdl_main_msvc@@YAHXZ") +int lol_sdl_main(int argc, char **argv); +int lol_sdl_main_msvc(int argc, char **argv); +#pragma comment(linker, "/alternatename:?lol_sdl_main@@YAHHPEAPEAD@Z" \ + "=?lol_sdl_main_msvc@@YAHHPEAPEAD@Z") +int lol_sdl_main(int argc, char **argv, char **envp); +int lol_sdl_main_msvc(int argc, char **argv, char **envp); +#pragma comment(linker, "/alternatename:?lol_sdl_main@@YAHHPEAPEAD0@Z" \ + "=?lol_sdl_main_msvc@@YAHHPEAPEAD0@Z") +# endif # endif #endif diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index 6bcfba6f..fa987074 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -43,7 +43,9 @@ extern IDirect3DDevice9 *g_d3ddevice; #if defined main # if defined _MSC_VER -# pragma comment(linker, "/alternatename:_lol_sdl_main=_lol_sdl_main_msvc") +int lol_sdl_main(); +int lol_sdl_main(int argc, char **argv); +int lol_sdl_main(int argc, char **argv, char **envp); # define WRAPPER lol_sdl_main_msvc # else int lol_sdl_main() __attribute__((weak)); @@ -53,13 +55,13 @@ int lol_sdl_main(int argc, char **argv, char **envp) __attribute__((weak)); # endif /* One of these wrappers will be overridden by the user's version */ + int WRAPPER() { return 0; } int WRAPPER(int argc, char **argv) { return 0; } int WRAPPER(int argc, char **argv, char **envp) { return 0; } int main(int argc, char *argv[]) { -printf("LOL OK\n"); int ret = 0; ret += lol_sdl_main(); ret += lol_sdl_main(argc, argv); diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 6cf49a7e..eda07aee 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -19,7 +19,7 @@ #include -int main(int argc, char **argv) +int main() { lol::TextTestRunner runner; bool success = runner.Run();