Build failed with w64devkit on Windows Platform
Closed this issue · 6 comments
I try to build this repo with w64devkit on windows, but failed with below error log.
Version Info:
Host OS: Windows 10 version: 22H2 (19045.4046)
w64devkit: w64devkit-1.21.0 (https://github.com/skeeto/w64devkit/releases/download/v1.21.0/w64devkit-1.21.0.zip)
Ninja: 1.11.1
Cmake: cmake-3.28.3-windows-x86_64
freetype: tag VER-2-13-2 of repo https://github.com/freetype/freetype, build and install to D:\freetype-2.13.2-win32
Configure command: > cmake -GNinja -DCMAKE_BUILD_TYPE=Release -B build/release -DFREETYPE_INCLUDE_DIRS=”D:\freetype-2.13.2-win32\include;D:\freetype-2.13.2-win32\include\freetype2” -DFREETYPE_LIBRARY=”D:\freetype-2.13.2-win32\lib\libfreetype.dll.a”
Build command: > cmake –build build/release
Error output log:
[1/3] Linking C executable _deps\sdl2_ttf-build\showfont.exe
FAILED: _deps/sdl2_ttf-build/showfont.exe
C:\Windows\system32\cmd.exe /C "cd . && D:\w64devkit\bin\cc.exe -O3 -DNDEBUG -mwindows _deps/sdl2_ttf-build/CMakeFiles/showfont.dir/showfont.c.obj -o _deps\sdl2_ttf-build\showfont.exe -Wl,--out-implib,_deps\sdl2_ttf-build\libshowfont.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lmingw32 _deps/sdl2_ttf-build/libSDL2_ttf.dll.a _deps/sdl2-build/libSDL2.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
D:\w64devkit\bin/ld.exe: D:/w64devkit/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o):crtexewin.c:(.text.startup+0xb1): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
[2/3] Linking C executable _deps\sdl2_ttf-build\glfont.exe
FAILED: _deps/sdl2_ttf-build/glfont.exe
C:\Windows\system32\cmd.exe /C "cd . && D:\w64devkit\bin\cc.exe -O3 -DNDEBUG -mwindows _deps/sdl2_ttf-build/CMakeFiles/glfont.dir/glfont.c.obj -o _deps\sdl2_ttf-build\glfont.exe -Wl,--out-implib,_deps\sdl2_ttf-build\libglfont.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lopengl32 -lmingw32 _deps/sdl2_ttf-build/libSDL2_ttf.dll.a _deps/sdl2-build/libSDL2.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
D:\w64devkit\bin/ld.exe: D:/w64devkit/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o):crtexewin.c:(.text.startup+0xb1): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
[3/3] Linking CXX executable src\SmallSDL2App.exe
FAILED: src/SmallSDL2App.exe
C:\Windows\system32\cmd.exe /C "cd . && D:\w64devkit\bin\c++.exe -O3 -DNDEBUG /subsystem:windows /entry:mainCRTStartup -mwindows src/CMakeFiles/SmallSDL2App.dir/Main.cpp.obj src/CMakeFiles/SmallSDL2App.dir/Application.cpp.obj src/CMakeFiles/SmallSDL2App.dir/Window.cpp.obj src/CMakeFiles/SmallSDL2App.dir/assets/manifests/app.rc.obj src/CMakeFiles/SmallSDL2App.dir/platform/windows/Resources.cpp.obj src/CMakeFiles/SmallSDL2App.dir/platform/windows/DPIHandler.cpp.obj -o src\SmallSDL2App.exe -Wl,--out-implib,src\libSmallSDL2App.dll.a -Wl,--major-image-version,0,--minor-image-version,0 _deps/sdl2_ttf-build/libSDL2_ttf.dll.a _deps/sdl2-build/libSDL2.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && C:\Windows\system32\cmd.exe /C "cd /D D:\20_gui\cpp-small-gui-project-sdl2\build\release\src && D:\cmake-3.28.3\bin\cmake.exe -E copy_if_different D:/20_gui/cpp-small-gui-project-sdl2/build/release/_deps/sdl2-build/SDL2.dll D:/20_gui/cpp-small-gui-project-sdl2/build/release/src && cd /D D:\20_gui\cpp-small-gui-project-sdl2\build\release\src && D:\cmake-3.28.3\bin\cmake.exe -E copy_if_different D:/20_gui/cpp-small-gui-project-sdl2/build/release/_deps/sdl2_ttf-build/SDL2_ttf.dll D:/20_gui/cpp-small-gui-project-sdl2/build/release/src && cd /D D:\20_gui\cpp-small-gui-project-sdl2\build\release\src && D:\cmake-3.28.3\bin\cmake.exe -E copy_directory D:/20_gui/cpp-small-gui-project-sdl2/src/assets D:/20_gui/cpp-small-gui-project-sdl2/build/release/src/../share""
D:\w64devkit\bin/ld.exe: cannot find /subsystem:windows: No such file or directory
D:\w64devkit\bin/ld.exe: cannot find /entry:mainCRTStartup: No such file or directory
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
for "FAILED: src/SmallSDL2App.exe",
I can using below patch to fix same as your commit Support MinGW in Windows
patch for src/platform/windows/CMakeLists.txt
-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /subsystem:windows /entry:mainCRTStartup")
+if (MINGW)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-subsystem,windows,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
+ set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++")
+else ()
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /subsystem:windows /entry:mainCRTStartup")
+endif ()
For "FAILED: _deps/sdl2_ttf-build/showfont.exe" and "FAILED: _deps/sdl2_ttf-build/glfont.exe",
Do we need a local patch to fix it? or any suggestion?
Hey, not sure about the issues related to SDL2_ttf, but I will have a look later.
Okay, I found the problem and updated the repository. In short it is related to the separately installed FreeType. The need for this is removed, as well as the problem solved, when using the SDL2_ttf provided FreeType version by setting SDL2TTF_VENDORED to TRUE.
set(SDL2TTF_VENDORED TRUE)Now MinGW works without a separate FreeType installation. Have a look at the updated main and let me know if all works for you ✌🏻
after sync main branch of repo, build and run worked.
Very nice 👍🏻