Twinklebear/ChameleonRT

Please support MSYS2 MINGW64

iahung opened this issue · 14 comments

Please support MSYS2 MINGW64

Do you mean distribute ChameleonRT binaries built with mingw64 through MSYS2 ?

Do you mean distribute ChameleonRT binaries built with mingw64 through MSYS2 ?

No, building from source on MSYS2 MINGW64. It's currently failed to build.

Can you post the errors? Which backend is failing?

Can you post the errors? Which backend is failing?

cmake configuration is fine:

$ cmake ..
-- Building for: Ninja
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
CMake Warning (dev) at C:/msys64/mingw64/share/cmake/Modules/ExternalProject.cmake:3091 (message):
  The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
  not set.  The policy's OLD behavior will be used.  When using a URL
  download, the timestamps of extracted files should preferably be that of
  the time of extraction, otherwise code that depends on the extracted
  contents might not be rebuilt if the URL changes.  The OLD behavior
  preserves the timestamps from the archive instead, but this is usually not
  what you want.  Update your project to the NEW behavior or specify the
  DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
  robustness issue.
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake/Modules/ExternalProject.cmake:4208 (_ep_add_download_command)
  cmake/glm.cmake:3 (ExternalProject_Add)
  CMakeLists.txt:19 (include)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found OpenGL: opengl32
-- Configuring done (2.0s)
-- Generating done (0.0s)
-- Build files have been written to: C:/msys64/home/Administrator/ChameleonRT/build

Building is also fine, but finally failed at linking:

[33/33] Linking CXX executable chameleonrt.exe
FAILED: chameleonrt.exe
cmd.exe /C "cd . && C:\msys64\mingw64\bin\c++.exe   CMakeFiles/chameleonrt.dir/main.cpp.obj -o chameleonrt.exe -Wl,--out-implib,libchameleonrt.dll.a -Wl,--major-image-version,0,--minor-image-version,0  util/libutil.a  util/display/libdisplay.a  -lSDL2  -lSDL2main  util/libutil.a  imgui/libimgui.a  C:/msys64/mingw64/lib/libSDL2.dll.a  C:/msys64/mingw64/lib/libSDL2main.a  -lshell32  -Wl,--undefined=WinMain  util/display/glad/libglad.a  -lopengl32  -lglu32  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../lib/libSDL2main.a(SDL_windows_main.c.obj):(.text+0x17a): undefined reference to `SDL_main'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

It's really foolish but I have encountered such problem before on MSYS2. The linking libraries order is mater on MSYS2:

msys2/MINGW-packages#16526

I see, so maybe SDLmain has to come before SDL for mingw. I've made that change in 33c7d1f , could you try it out? I don't have msys/mingw set up locally

I see, looking at the error again it might actually be because I set SDL_MAIN_HANDLED for Windows/MSVC. Maybe that shouldn't be set for MSYS. Could you try f8db71a , which won't set that var for MSYS?

I see, looking at the error again it might actually be because I set SDL_MAIN_HANDLED for Windows/MSVC. Maybe that shouldn't be set for MSYS. Could you try f8db71a , which won't set that var for MSYS?

Doesn't work.

@Biswa96 Please have a look at this. undefined reference to 'SDL_main' on MSYS2 is annoying.

Generally, that kind of error is solved with -Dmain=SDL_main compiler flag. But it does not work in my case. It comes from here 👇

$ sdl2-config --cflags
-IF:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main

$ pkg-config --cflags sdl2
-IF:/msys64/ucrt64/include/SDL2 -Dmain=SDL_main

Somehow the following change works, I don't know the reason 🤷

diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt
index 963488f..93828e6 100644
--- a/util/CMakeLists.txt
+++ b/util/CMakeLists.txt
@@ -44,12 +44,6 @@ if (NOT TARGET SDL2::SDL2)
     endif()
 endif()
 
-# Put SDL2main before SDL2
-if (WIN32)
-    target_link_libraries(util PUBLIC
-        SDL2::SDL2main)
-endif()
-
 target_link_libraries(util PUBLIC
     SDL2::SDL2)

Interesting, so it sounds like for MSYS2 we should not link SDL2main at all. I've removed that and it looks like things are ok on the MSVC side, can you try out the latest commit 602eda3 on MSYS2?

Interesting, so it sounds like for MSYS2 we should not link SDL2main at all. I've removed that and it looks like things are ok on the MSVC side, can you try out the latest commit 602eda3 on MSYS2?

Confirm that it's linking fine now.

Great!