Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何避免在通过CMake构建时链接不必要的windows库?_C++_C_Cmake - Fatal编程技术网

C++ 如何避免在通过CMake构建时链接不必要的windows库?

C++ 如何避免在通过CMake构建时链接不必要的windows库?,c++,c,cmake,C++,C,Cmake,我注意到,在Windows上使用CMake构建时,它会自动为所有项目添加一些不必要的库 示例(部分ldd输出): 我的编译器(带有MCF线程和SEH的MinGW-w64)的CMAKE_C_标准_库和CMAKE_CXX_标准_库的默认值都是-lkernel32-luser32-lgdi32-lwinspool-lshell32-lole32-loleaut32-luuid-lcomdlg32-ladvapi32。至于控制台应用程序,我很确定它不需要gdi32和其他许多应用程序有没有办法在不接触变量

我注意到,在Windows上使用CMake构建时,它会自动为所有项目添加一些不必要的库

示例(部分ldd输出):


我的编译器(带有MCF线程和SEH的MinGW-w64)的
CMAKE_C_标准_库
CMAKE_CXX_标准_库
的默认值都是
-lkernel32-luser32-lgdi32-lwinspool-lshell32-lole32-loleaut32-luuid-lcomdlg32-ladvapi32
。至于控制台应用程序,我很确定它不需要
gdi32
和其他许多应用程序有没有办法在不接触变量的情况下禁用这些库的链接?我想避免在现代CMAKE和基于目标的配方时代接触任何变量。

ldd
在Windows上?你从哪里得到的?Binutils附带任何Windows GCC发行版。Git Bash或MSYS shell附带了一些其他工具。
ldd
不是binutils的一部分
ld
是binutils的一部分,
ldd
是glibc的一部分。但我知道你没有安装glibc,因为你在Windows上。好吧,那就糟糕的命名吧。无论如何,任何Windows GCC发行版都打包了很多工具(在
mingw64/bin
中有100多个可执行文件)
哪个ldd
报告了
/usr/bin/ldd
,所以这一个来自Git Bash。相关:
$ 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)