Re: [hatari-devel] Windows MSYS MinGW64 Build Failure

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


Am Fri, 26 Mar 2021 10:17:49 -0500
schrieb Chang Chong <codemonkey2x@xxxxxxxxx>:

> 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
>     OUTPUT_VARIABLE DETECTED_SDL_CFLAGS
>     ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
> if(DETECTED_SDL_CFLAGS)
>     add_definitions(${DETECTED_SDL_CFLAGS})
>     # message(STATUS "Additional CFLAGS of SDL:
> ${DETECTED_SDL_CFLAGS}") endif(DETECTED_SDL_CFLAGS)
> 
> output:
> 
> $ pkg-config --cflags-only-other sdl2
>     -Dmain=SDL_main
> 
> 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.

I've once tried to compile Hatari with MSYS, too, and ran into similar
problems. The problem with "main" can be worked around with running
cmake like this, I think:

 CFLAGS="-Umain" cmake -G "Unix Makefiles" .

However, I then also hit some other weird problems there (SDL header
files try to include the "memory.h" system header, but end up in
including the memory.h from Hatari), so I finally gave up. That
toolchain is simply not very suitable for compiling Hatari, I think.

 Thomas



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