gpt4 book ai didi

c++ - 在 CMake 中,指定所有可执行文件 target_link_libraries 某些库

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:14:46 25 4
gpt4 key购买 nike

在 CMake 中,有没有办法指定我所有的可执行文件都链接到某个库?基本上我希望我所有的可执行文件都链接到 tcmalloc 和分析器。简单地指定 -ltcmalloc 和 -lprofiler 不是一个好的解决方案,因为我想让 CMake 以可移植的方式找到库的路径。

最佳答案

您可以使用您自己的函数覆盖内置的 add_executable 函数,它总是添加所需的链接依赖项:

macro (add_executable _name)
# invoke built-in add_executable
_add_executable(${ARGV})
if (TARGET ${_name})
target_link_libraries(${_name} tcmalloc profiler)
endif()
endmacro()

关于c++ - 在 CMake 中,指定所有可执行文件 target_link_libraries 某些库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10555706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com