如何找到一个图书馆与cmake? [英] How to find a library with cmake?
问题描述
要将可执行文件与位于标准位置的库链接,可以在CmakeLists.txt文件中执行以下操作:
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)
如果正在链接的库位于
/usr/local/lib/libOpenMeshCore.dylib
但是,在这种情况下,库位于
However, in this case the library resides under
/usr/local/lib/OpenMesh/libOpenMeshCore.dylib
我如何指定target_link_libraries应该真的链接到一个库放置在sibdirectory?我不知道target_link_libraries有一些有用的选项,可以指定该库位于标准位置的子目录中,例如
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)
如果不可能,有没有办法使用find_library搜索 / usr / local / lib
递归,包括给定库文件的子目录?
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?
推荐答案
您可以向 find_library
添加不同的目录。要使用此库,请通过 cmake -DFOO_PREFIX = / some / path ...
调用cmake。
You can add different directories to find_library
. To use this library call cmake by cmake -DFOO_PREFIX=/some/path ...
.
find_library( CPPUNIT_LIBRARY_DEBUG NAMES cppunit cppunit_dll cppunitd cppunitd_dll
PATHS ${FOO_PREFIX}/lib
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
PATH_SUFFIXES debug )
find_library( CPPUNIT_LIBRARY_RELEASE NAMES cppunit cppunit_dll
PATHS ${FOO_PREFIX}/lib
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
PATH_SUFFIXES release )
if(CPPUNIT_LIBRARY_DEBUG AND NOT CPPUNIT_LIBRARY_RELEASE)
set(CPPUNIT_LIBRARY_RELEASE ${CPPUNIT_LIBRARY_DEBUG})
endif(CPPUNIT_LIBRARY_DEBUG AND NOT CPPUNIT_LIBRARY_RELEASE)
set( CPPUNIT_LIBRARY debug ${CPPUNIT_LIBRARY_DEBUG}
optimized ${CPPUNIT_LIBRARY_RELEASE} )
# ...
target_link_libraries(foo ${CPPUNIT_LIBRARY})
这篇关于如何找到一个图书馆与cmake?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!