librw icon indicating copy to clipboard operation
librw copied to clipboard

Resolve WinMain linking issues with CMake

Open ccawley2011 opened this issue 4 years ago • 7 comments

Follow up to PR #77. SDL2 now works, but D3D9 is still broken.

Possibly related:

  • https://forum.qt.io/topic/126534/qt-6-undefined-reference-to-winmain-on-mingw
  • https://bugreports.qt.io/browse/QTBUG-93671

ccawley2011 avatar Jul 05 '21 15:07 ccawley2011

I created a branch on my fork that adds mingw CI with github actions: https://github.com/madebr/librw/tree/ga_mingw Github actions result at https://github.com/madebr/librw/actions/runs/1002476846 It has the behavior described in your initial comment: glfw/SDL2 works, d3d9 does not.

I find it weird that glfw works while d3d9 does not. Their respective librw_skeletonlibraries are both providing a WinMain symbol in a static library. What is different between them?

madebr avatar Jul 05 '21 22:07 madebr

I find it weird that glfw works while d3d9 does not. Their respective librw_skeletonlibraries are both providing a WinMain symbol in a static library. What is different between them?

I think it's because the GLFW backend has a standard main() function that can be used with MinGW's default WinMain implementation, while the Win32 backend doesn't have one and the one in the SDL backend gets renamed when SDL_MAIN_HANDLED is not defined.

ccawley2011 avatar Jul 05 '21 23:07 ccawley2011

@ccawley2011 Please re-check my ga_mingw branch at https://github.com/madebr/librw/tree/ga_mingw I got it working in a (so I believe) cleaner way by using linker options. github action results at https://github.com/madebr/librw/actions/runs/1002584126

madebr avatar Jul 05 '21 23:07 madebr

@ccawley2011 Please re-check my ga_mingw branch at https://github.com/madebr/librw/tree/ga_mingw I got it working in a (so I believe) cleaner way by using linker options. github action results at https://github.com/madebr/librw/actions/runs/1002584126

This seems to work with the 64-bit mingw-w64 toolchain, but not with MinGW32 or the 32-bit mingw-w64 toolchain.

ccawley2011 avatar Jul 06 '21 18:07 ccawley2011

@ccawley2011 Please re-check my ga_mingw branch at https://github.com/madebr/librw/tree/ga_mingw I got it working in a (so I believe) cleaner way by using linker options. github action results at https://github.com/madebr/librw/actions/runs/1002584126

This seems to work with the 64-bit mingw-w64 toolchain, but not with MinGW32 or the 32-bit mingw-w64 toolchain.

I got it working for all configs. See https://github.com/madebr/librw/actions/runs/1006420251 for the logs. I also added the ability to switch between static and shared runtime (this also includes static SDL2/glfw). Is it okay for you if I open a pr with these commits (I have to rewrite the commit history)?

madebr avatar Jul 07 '21 01:07 madebr

I got it working for all configs. See https://github.com/madebr/librw/actions/runs/1006420251 for the logs. I also added the ability to switch between static and shared runtime (this also includes static SDL2/glfw).

Thanks, I've tested the new changes and it works for me as well. I just have one additional suggested change for building with clang:

index 7c7c27c..572e4b2 100644
--- a/cmake/UseStaticRuntime.cmake
+++ b/cmake/UseStaticRuntime.cmake
@@ -6,6 +6,8 @@ endif()

 if(CMAKE_C_COMPILER_ID MATCHES "^GNU$")
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static")
+elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
 endif()

 if(WIN32)

Is it okay for you if I open a pr with these commits (I have to rewrite the commit history)?

Sure, go ahead.

ccawley2011 avatar Jul 07 '21 13:07 ccawley2011

+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")

Thanks. I wasn't sure whether -static also meant static libgcc and libstdc++

Is it okay for you if I open a pr with these commits (I have to rewrite the commit history)?

Sure, go ahead.

I will post it in the coming days and tag you.

madebr avatar Jul 07 '21 13:07 madebr