I have noticed that when building with CMake on Windows, it automatically adds some unnecessary libraries for all projects.
Example (partial ldd output):
$ ldd ./build/release/bin/program.exe
ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffee1180000)
KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffee0d00000)
KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffede3b0000)
msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7ffee0120000)
libstdc++-6.dll => /c/mingw64/mingw64/bin/libstdc++-6.dll (0x6fc40000)
mcfgthread-12.dll => /c/mingw64/mingw64/bin/mcfgthread-12.dll (0x6c080000)
libboost_filesystem-mt.dll => /c/mingw64/mingw64/bin/libboost_filesystem-mt.dll (0x638c0000)
ADVAPI32.dll => /c/WINDOWS/System32/ADVAPI32.dll (0x7ffedf230000)
sechost.dll => /c/WINDOWS/System32/sechost.dll (0x7ffee0ef0000)
RPCRT4.dll => /c/WINDOWS/System32/RPCRT4.dll (0x7ffee0230000)
libboost_program_options-mt.dll => /c/mingw64/mingw64/bin/libboost_program_options-mt.dll (0x678c0000)
libgcc_s_seh-1.dll => /c/mingw64/mingw64/bin/libgcc_s_seh-1.dll (0x61440000)
WS2_32.dll => /c/WINDOWS/System32/WS2_32.dll (0x7ffee01c0000)
WSOCK32.dll => /c/WINDOWS/SYSTEM32/WSOCK32.dll (0x7ffedbfd0000)
libcrypto-1_1-x64.dll => /c/mingw64/mingw64/bin/libcrypto-1_1-x64.dll (0x67e00000)
USER32.dll => /c/WINDOWS/System32/USER32.dll (0x7ffee0350000)
win32u.dll => /c/WINDOWS/System32/win32u.dll (0x7ffede190000)
GDI32.dll => /c/WINDOWS/System32/GDI32.dll (0x7ffee04f0000)
gdi32full.dll => /c/WINDOWS/System32/gdi32full.dll (0x7ffede1c0000)
msvcp_win.dll => /c/WINDOWS/System32/msvcp_win.dll (0x7ffedee30000)
ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7ffedeed0000)
libssl-1_1-x64.dll => /c/mingw64/mingw64/bin/libssl-1_1-x64.dll (0x6d480000)
The default values of both CMAKE_C_STANDARD_LIBRARIES
and CMAKE_CXX_STANDARD_LIBRARIES
for my compiler (MinGW-w64 with MCF threads and SEH) are -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
. As for console application, I'm pretty sure it does not need gdi32
and many others. Is there any way to disable linking these libraries, without touching CMAKE_
variables? I would like to avoid touching any variables in the era of modern CMake and target-based recipes.