[hatari-devel] Windows MSYS MinGW64 Build Failure |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: [hatari-devel] Windows MSYS MinGW64 Build Failure
- From: Chang Chong <codemonkey2x@xxxxxxxxx>
- Date: Fri, 26 Mar 2021 10:17:49 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:subject:message-id:date:to :mime-version; bh=Ux4nFuhuXk31xudW+X9clC2BK+rALKEv74L53TxBA4Q=; b=Qr5sbVqZ/vF8VfLErPNTVQTUrY646EGsqlEHU52yojJaOFzoF1WnUOFtx0jiercHd9 bKpHiBHR7L7nTrZEQ2IWqgpHorbBhTFudPzAm/Gu+osQm30qMvWWyRFV3N40xllVF6EM 0vDWqP7mQRfgaKVieUk+nGLRigDUeEQ/gIwF+bagVSOQHUGVvsMoft4FKMRnpX5fCgDc 2iRfeZc0REBKQAE8agxSYEK8jgl3m3SqQpSBihsorV3w5z6O9vn3f7JyYxvtFT6kuuPR u9JfdtSnUZG53oE6sJ+TIKSdygiSFo6DEnGABeMDui8gJegDRlRoTvSBqXx/aUwI3IZP euvg==
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. 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.
Thanks