我正在使用 debian 和 cmake 在 C++ 中构建应用程序。该项目进一步基于一些静态库 ( ITK ),它们存储在文件夹中 libname-x.y.a
其中 x
和 y
表示版本号。
包含库的文件夹被添加到 CMake 的 LINK_DIRECTORIES
,库被添加到 TARGET_LINK_LIBRARIES
作为 libname-x.y.a
。使用make
构建项目时,链接器/usr/bin/ld
输出cannot find -llibname
,即没有版本后缀。
将库添加到没有版本后缀的 TARGET_LINK_LIBRARIES
时,项目也不会构建。
有人知道如何解决这个问题吗?
附言在 Windows 上,编译和链接工作。
最佳答案
The solution is to use
find_library
and pass the result from that totarget_link_libraries
. This is a bit more work up front but will make the system more pleasant to use.
摘自常见 CMake 反模式列表,不检查就使用库部分:
http://voices.canonical.com/jussi.pakkanen/2013/03/26/a-list-of-common-cmake-antipatterns/
关于linux - CMake:链接静态库与文件名中的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33741203/