librw icon indicating copy to clipboard operation
librw copied to clipboard

Fix compilation with MinGW32

Open ccawley2011 opened this issue 4 years ago • 5 comments

There is still one compilation failure remaining in the playground application, which occurs when building with Direct3D or SDL2 (but not GLFW):

d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

The same issue can be observed with MinGW-w64 as well:

D:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.3.0/../../../../i686-w64-mingw32/bin/ld.exe: D:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/10.3.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o): in function `main':
C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain@16'

ccawley2011 avatar Jun 29 '21 16:06 ccawley2011

I'm looking into #76 with cmake. It looks like Android also needs SDL_MAIN_HANDLED defined for dumprwtree (not useful on Android because it is a cli tool, but good to know) and other targets. I propose to do the following cmake change instead. Instead of https://github.com/aap/librw/blob/b2ceadc9f2e478c5a470f625a0ee5b08ad12efb6/src/CMakeLists.txt#L160, do:

        target_compile_definitions(librw
            PUBLIC
                LIBRW_SDL2
                SDL_MAIN_HANDLED
        )

I guess something similar can be done in the premake script.

We should probably add a call to SDL_SetMainReady at the appropriate places. See https://wiki.libsdl.org/SDL_SetMainReady

madebr avatar Jun 30 '21 00:06 madebr

The SDL_MAIN_HANDLED changes have been separated into PR #83.

ccawley2011 avatar Jul 05 '21 15:07 ccawley2011

Can you please update this PR's title + description? This pr is not doing anything mingw related anymore. #87 adds mingw support (albeit not to the premake script)

madebr avatar Jul 09 '21 00:07 madebr

Can you please update this PR's title + description? This pr is not doing anything mingw related anymore. #87 adds mingw support (albeit not to the premake script)

This PR is still necessary for the original MinGW (https://osdn.net/projects/mingw/).

ccawley2011 avatar Jul 09 '21 00:07 ccawley2011

Indeed. And with #87, no more WinMain linking errors.

madebr avatar Jul 09 '21 01:07 madebr