在 CMake 中,指定某些库target_link_libraries的所有可执行文件
In CMake, specify all executables target_link_libraries certain libraries
在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()
您可以在 CMake 中编写一个函数/宏来为您完成工作。
function(setup name sources
add_executable(name sources)
target_link_library(name tcmalloc profiler)
endfunction(setup)
setup(foo foo.c)
setup(bar bar.c)
有关详细信息,请查看文档。
相关文章:
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- C++ MFC Libraries in Travis CI
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- qt QWidget::closeEvent link issue
- Ardunio Uart class & Libraries
- 在 R 中调用"multi file C++ code with external libraries referenced"
- CMake:如何添加不是"link"依赖项的依赖项
- Windows 上的 Clang/LLVM 7 和 8 多次初始化内联静态数据成员(使用 link.exe 和 lld-
- Visual Studio 中的 lcr 游戏 c++ LINK 2019 错误
- Link Paho MQTT CMake
- 链接 boost 库时"Error while loading shared libraries"引发的,除了我无法使用 root 访问权限来修复它
- Mac OS c++ Link OpenCV and libtiff
- CMake nested libraries
- 如何处理"Cmake Error: Unable to find the requested Boost libraries"?
- cmake_list中的link openssl静态
- 如何修复'The procedure entry point SDL_RWclose could not be located in the dynamic link library'
- Bjarne Stroustrup在他的FAQ中"foundation libraries"是什么意思?
- Connflicting C++ libraries
- libsqlite3.dylib link with CMake
- xcode:添加链接器标志和"link binary with libraries"的区别