Skip to content

Instantly share code, notes, and snippets.

@qis
Last active October 17, 2020 18:08
Show Gist options
  • Save qis/d26e9d72a58e6ce0ebacbc7fad65228c to your computer and use it in GitHub Desktop.
Save qis/d26e9d72a58e6ce0ebacbc7fad65228c to your computer and use it in GitHub Desktop.

Windows Clang

https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features
https://libcxx.llvm.org/docs/UsingLibcxx.html

See _LIBCPP_NO_VCRUNTIME.

Paths

https://gitlab.kitware.com/cmake/cmake/-/blob/v3.17.3/Modules/InstallRequiredSystemLibraries.cmake#L339-358

Microsoft/STL

C++ Standard Library: msvcprtd.lib (debug), msvcprt.lib (release)

Environment

Set include paths instead of passing -i "…" to rc.

set INCLUDE=C:/Program Files/LLVM/lib/clang/11.0.0/include
set INCLUDE=%INCLUDE%;C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/include
set INCLUDE=%INCLUDE%;C:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/ucrt
set INCLUDE=%INCLUDE%;C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/shared
set INCLUDE=%INCLUDE%;C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/um

Set include paths instead of passing -isystem "…" to clang and clang++.

set C_INCLUDE_PATH=%INCLUDE%
set CPLUS_INCLUDE_PATH=%INCLUDE%

Set library paths instead of passing -libpath:"…" to lld-link.

set LIB=C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/lib/x64
set LIB=%LIB%;C:/Program Files (x86)/Windows Kits/10/Lib/10.0.18362.0/ucrt/x64
set LIB=%LIB%;C:/Program Files (x86)/Windows Kits/10/Lib/10.0.18362.0/um/x64

Resources

"C:/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/rc.exe" -nologo ^
  -fo main.rc.res main.rc

Debug

clang++ -std=c++20 -O0 -D_DEBUG -D_DLL -D_MT -MD -nostdinc -g -Xclang -gcodeview ^
  -MT main.cpp.obj -MF main.cpp.obj.d -o main.cpp.obj -c main.cpp

lld-link -out:main.exe main.cpp.obj main.rc.res -implib:main.lib -pdb:main.pdb -version:0.0 -nodefaultlib -debug ^
  vcruntimed.lib ucrtd.lib msvcrtd.lib kernel32.lib uuid.lib user32.lib

Release

clang++ -std=c++20 -O3 -DNDEBUG -D_DLL -D_MT -MD -nostdinc ^
  -MT main.cpp.obj -MF main.cpp.obj.d -o main.cpp.obj -c main.cpp

lld-link -out:main.exe main.cpp.obj main.rc.res -implib:main.lib -version:0.0 -nodefaultlib ^
  libvcruntime.lib ucrt.lib msvcrt.lib kernel32.lib uuid.lib user32.lib

RelWithDebInfo

clang++ -std=c++20 -O2 -DNDEBUG -D_DLL -D_MT -MD -nostdinc -g -Xclang -gcodeview ^
  -MT main.cpp.obj -MF main.cpp.obj.d -o main.cpp.obj -c main.cpp

lld-link -out:main.exe main.cpp.obj main.rc.res -implib:main.lib -pdb:main.pdb -version:0.0 -nodefaultlib -debug ^
  libvcruntime.lib ucrt.lib msvcrt.lib kernel32.lib uuid.lib user32.lib

Manifest

Use ;1 for an EXE file and ;2 for a DLL file.

"C:/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64/mt.exe" -nologo ^
  -manifest main.manifest -outputresource:main.exe;1

Notes

echo "" | clang -E -x c++ - -v -stdlib=libc++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment