英文:
What does cmake do with Unnecessary links
问题
- 我在清理/重构一个相当古老的项目,我意识到他们犯了一个错误(?),在所有的CMakeLists.txt文件中添加了不必要的链接:
LIST(APPEND ${PROJECT_NAME}_LIBRARIES RecursiveLy_generated_list_with_unnecessarystuff)
target_link_libraries(sample PUBLIC ${${PROJECT_NAME}_LIBRARIES})
我用一个仅包含必要链接的列表替换了原列表,编译时间明显减少了。
-
所以我想知道,当链接的库的符号未被使用时,
cmake
会做什么? -
我还清理了包含目录(项目的所有.h文件都被递归添加了(许多是不需要的)),
cmake
是否认为这些符号被使用,因为它们出现在头文件中,即使这些头文件没有被#include
进来?
英文:
I'm cleaning/refactoring a quite old project and I realized they made the mistake(?) of adding unnecessary links to the targets in all the CMakeLists.txt files:
LIST(APPEND ${PROJECT_NAME}_LIBRARIES RecursiveLy_generated_list_with_unnecessarystuff)
target_link_libraries(sample PUBLIC ${${PROJECT_NAME}_LIBRARIES})
I replaced the list by one that contains only the necessary links and the compilation time got noticeably reduced.
-
So I'm wondering what does
cmake
do when the symbols of a library that was linked are not used? -
I also cleaned the include directories (ALL the .h files of the project were recursively added (many not needed)), did
cmake
think the symbols were used because they appeared in the headers even if this headers were not#include
d ?
答案1
得分: 2
> "cmake处理不必要的链接时会执行什么操作"
将正确的命令行选项传递给编译器。
> "当链接的库的符号未被使用时,cmake会执行什么操作"
什么也不做。CMake甚至不知道库的符号是否被使用。CMake不会链接您的代码,编译器会。
> "是否因为这些符号出现在头文件中而未被包含在内,CMake会认为这些符号被使用了吗?"
不,CMake不知道符号在何处被使用。CMake不了解头文件的内容。CMake创建要运行的命令列表。要运行哪些命令取决于CMakeLists.txt中的内容。
英文:
> What does cmake do with Unnecessary links
Passes proper command line options to the compiler.
> what does cmake do when the symbols of a library that was linked are not used?
Nothing. CMake is not even aware that symbols of a library are or are not used. CMake does not link your code, compiler does.
> did cmake think the symbols were used because they appeared in the headers even if this headers were not #included ?
No, CMake is unaware of what symbols are used where. CMake is unaware of the content of header files. CMake creates a list of commands to run. What commands to run depends on what is written in CMakeLists.txt.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论