4

I would like to have complete Win32 development toolchain without Microsoft SDKs. mingw64 works, but its linker is very slow. As an alternative, I am trying to use clang for windows. I can get clang 7.0.1 (but not 8.0.0) work with mingw headers/libraries, however only using mingw's ld.exe. If I force ldd.exe to be used (-fuse-ld=lld), everything compiles and links fine, but the application immediately crashes when started. Is there anything I can do here, like change something in the commandline?

This is how commandline and --verbose for the link step looks like:

Linking...
clang++ -static -o "C:\upp\out\MyApps\CLANG.Debug.Debug_Full\main.exe"
    -ggdb -L"C:\upp\bin/mingw64/64/x86_64-w64-mingw32/lib"
    -L"C:\uppbin/mingw64/64/opt/lib" -L"C:\upp\bin/SDL2/lib/x64" 
    -L"C:\upp\bin/pgsql/x64/bin"
    -L"C:\upp\bin/mysql/lib64"
    -Wl,--stack,20000000 --verbose -target x86_64-pc-windows-gnu
    -fuse-ld=lld
    "C:/upp/out/MyApps/main/CLANG.Debug.Debug_Full.Main\main.o"
    -Wl,--start-group  -Wl,--end-group
clang version 7.0.1 (tags/RELEASE_701/final)
Target: x86_64-pc-windows-gnu
Thread model: posix
InstalledDir: C:\xxx\LLVM2\bin
 "C:\\xxx\\LLVM2\\bin\\ld.lld" -m i386pep -Bstatic
 -o "C:\\upp\\out\\MyApps\\CLANG.Debug.Debug_Full\\main.exe"
 "C:\\upp\\bin\\mingw64\\64\\x86_64-w64-mingw32\\lib\\crt2.o"
 "C:\\upp\\bin\\mingw64\\64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\crtbegin.o"    
 "-LC:\\upp\\bin/mingw64/64/x86_64-w64-mingw32/lib"
 "-LC:\\upp\\bin/mingw64/64/opt/lib"
 "-LC:\\upp\\bin/SDL2/lib/x64" "-LC:\\upp\\bin/pgsql/x64/bin"
 "-LC:\\upp\\bin/mysql/lib64"
 "-LC:\\upp\\bin\\mingw64\\64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0" 
 "-LC:\\upp\\bin\\mingw64\\64\\x86_64-w64-mingw32\\lib"
 "-LC:\\upp\\bin\\mingw64\\64\\lib"
 "-LC:\\upp\\bin\\mingw64\\64\\x86_64-w64-mingw32/sys-root/mingw/lib"
 --stack 20000000
 "C:/upp/out/MyApps/main/CLANG.Debug.Debug_Full.Main\\main.o"
 --start-group --end-group -lstdc++ --start-group -lmingw32
 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32
 -luser32 -lkernel32 --end-group
 "C:\\upp\\bin\\mingw64\\64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\crtend.o"
Mirek Fidler
  • 330
  • 1
  • 9
  • This might be of some help: https://stackoverflow.com/questions/54382944/unable-to-run-windows-binary-compiled-with-clang-lld-mingw – ConsistentProgrammer Apr 29 '19 at 10:43
  • Using `g++ -Wl,--subsystem,windows -mwindows -fuse-ld=lld` for linking with the latest [WinLibs-MinGW-w64](https://github.com/brechtsanders/winlibs_mingw/releases/tag/12.2.0-14.0.6-10.0.0-msvcrt-r2) works fine for me. Decreased debug executable linking duration from over 4 minutes to 1 second. (!) – xamid Oct 07 '22 at 07:16

1 Answers1

0

The llvm-mingw toolchain is very easy to use and provides latest clang / libc++ / lld without any dependency on the Microsoft headers: https://github.com/mstorsjo/llvm-mingw

It links against the Microsoft ucrt and as such is compatible with MSVC-built DLLs (for the C API / ABI, not the C++ since it uses a different standard library implementation)

Jean-Michaël Celerier
  • 7,412
  • 3
  • 54
  • 75