如何使用cmake查找库?
要将可执行文件与驻留在标准位置的库链接,可以在 CmakeLists.txt 文件中执行以下操作:
create_executable(generate_mesh generate_mesh.cpp)
target_link_libraries(generate_mesh OpenMeshCore)
如果要链接的库放置
/usr/local/lib/libOpenMeshCore.dylib
在在
/usr/local/lib/OpenMesh/libOpenMeshCore.dylib
如何指定 target_link_libraries 应该真正链接到放置在 sibdirectory 中的库?我想知道 target_link_libraries 有一些有用的选项,可以指定该库位于标准位置的子目录中,例如,
target_link_libraries(generate_mesh OpenMesh/OpenMeshCore)
如果不可能,是否有办法使用 find_library 来搜索 /usr/local/lib< /code> 递归地,包括它的子目录,对于给定的库文件?
To link an executable with a library that resides in a standard location, one can do the following in a CmakeLists.txt file:
create_executable(generate_mesh generate_mesh.cpp)
target_link_libraries(generate_mesh OpenMeshCore)
This would work if the library, that is being linked against, was placed in
/usr/local/lib/libOpenMeshCore.dylib
However, in this case the library resides under
/usr/local/lib/OpenMesh/libOpenMeshCore.dylib
How can I specify that target_link_libraries should really link against a library placed in a sibdirectory? I wonder there is some useful option to target_link_libraries that would specify that the library is in a subdirectory in a standandard location, e.g.
target_link_libraries(generate_mesh OpenMesh/OpenMeshCore)
If that is not possible, is there a way to use find_library to search /usr/local/lib
recursively, including its sub-directories, for the given library file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将不同的目录添加到
find_library
。要使用此库,请通过cmake -DFOO_PREFIX=/some/path ...
调用 cmake。You can add different directories to
find_library
. To use this library call cmake bycmake -DFOO_PREFIX=/some/path ...
.