Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linker 如何使用cmake查找库?_Linker_Cmake_Subdirectory - Fatal编程技术网

Linker 如何使用cmake查找库?

Linker 如何使用cmake查找库?,linker,cmake,subdirectory,Linker,Cmake,Subdirectory,要将可执行文件与驻留在标准位置的库链接,可以在CmakeLists.txt文件中执行以下操作: create_executable(generate_mesh generate_mesh.cpp) target_link_libraries(generate_mesh OpenMeshCore) 如果将链接所针对的库放置在 /usr/local/lib/libOpenMeshCore.dylib 但是,在这种情况下,库位于 /usr/local/lib/OpenMesh/libOpenMes

要将可执行文件与驻留在标准位置的库链接,可以在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_库应真正链接到放置在SIB目录中的库?我想知道是否有一些有用的选项可以针对_link_库,指定库位于标准位置的子目录中,例如

target_link_libraries(generate_mesh OpenMesh/OpenMeshCore)

如果不可能,是否有方法使用find_library递归搜索给定库文件的
/usr/local/lib
,包括其子目录

您可以将不同的目录添加到
查找库
。要使用此库,请通过
cmake-DFOO\u PREFIX=/some/path…
调用cmake

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})