[hatari-devel] Windows MSYS MinGW64 Build Failure

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]

I wanted to share my observations while trying to build a windows binary using msys2/mingw64 on a windows 10 machine. I installed SDL 2.0.14 via pacman.

I used the cmake generator “MSYS Makefiles” (UNIX Makefiles would work as well). No issues getting the project configured with cmake and SDL2. However, most binaries fail to link with the error message:

mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_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'
collect2.exe: error: ld returned 1 exit status

After some troubleshooting, I found the issue is with a define in the compilation -Dmain=SDL_main. This is set by the pkg-config call in the main CMakeLists.txt:

# Additional CFLAGS suggested by the SDL library:
execute_process(COMMAND pkg-config --cflags-only-other sdl2
    # message(STATUS "Additional CFLAGS of SDL: ${DETECTED_SDL_CFLAGS}")


$ pkg-config --cflags-only-other sdl2

The pkg-config executable is from /mingw64/bin/pkg-config.exe.

The solution is to add ${SDL2_LIBRARY} to the target_link_libraries for all the failing executables. This will resolve the missing symbols. That’s what I did and I’ve been testing out the hatari.exe application so far without any issues.

I do have additional observations when trying to cross compile a windows executable through linux. Again, it’s centered around SDL2 and pkg-config. I’m not including it in this email as I wanted to keep it to this specific issue.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/