.so以后的数字,如何在cmake的find_library中匹配它们?在链接共享对象,其错误被发现作为子依赖性

问题描述:

鉴于
ls -lrt /usr/lib/libvpx*结果.so以后的数字,如何在cmake的find_library中匹配它们?在链接共享对象,其错误被发现作为子依赖性

lrwxrwxrwx 1 root root 15 Feb 9 2012 /usr/lib/libvpx.so.1.0 ->libvpx.so.1.0.0
lrwxrwxrwx 1 root root 15 Feb 9 2012 /usr/lib/libvpx.so.1 -> libvpx.so.1.0.0
-rw-r--r-- 1 root root 646120 Feb 9 2012 /usr/lib/libvpx.so.1.0.0

ls -lrt /usr/lib/libschroedinger*结果

lrwxrwxrwx 1 root root 29 Feb 8 2012 /usr/lib/libschroedinger-1.0.so.0 ->libschroedinger-1.0.so.0.11.0
-rw-r--r-- 1 root root 774044 Feb 8 2012 /usr/lib/libschroedinger-1.0.so.0.11.0

ls -lrt /usr/lib/libgsm*结果

lrwxrwxrwx 1 root root 16 Nov 5 2009 /usr/lib/libgsm.so.1 -> libgsm.so.1.0.12
-rw-r--r-- 1 root root 50680 Nov 5 2009 /usr/lib/libgsm.so.1.0.12

这是在方法1 this question中发现的问题的可能解决方案。你可能不会提及这一点。

可能的解决方案
正如我在父母的问题提到的,我们可以根据需要添加三个find_library()功能。以下是内容的CMakeLists.txt

可能的解决方案1A

find_library(VPX_LIBRARIES NAMES libvpx.so.1 PATHS /usr/lib/)
find_library(SCHROEDINGER_LIBRARIES NAMES libschroedinger-1.0.so.0-1.0 PATHS /usr/lib/) find_library(GSM_LIBRARIES NAMES libgsm.so.1 PATHS /usr/lib/)

target_link_libraries(MyLibraryOrMyExecutable ${VPX_LIBRARIES} ${SCHROEDINGER_LIBRARIES} ${GSM_LIBRARIES})

可能的解决方案1B

find_library(VPX_LIBRARIES NAMES vpx PATHS /usr/lib/)
find_library(SCHROEDINGER_LIBRARIES NAMES schroedinger-1.0 PATHS /usr/lib/) find_library(GSM_LIBRARIES NAMES gsm PATHS /usr/lib/)

target_link_libraries(MyLibraryOrMyExecutable ${VPX_LIBRARIES} ${SCHROEDINGER_LIBRARIES} ${GSM_LIBRARIES})

错误
我得到同样的错误了两种解决方案1A和1b

CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files:

GSM_LIBRARIES
linked by target "MyLibraryOrMyExecutable" in directory /someDirectory

SCHROEDINGER_LIBRARIES
linked by target "MyLibraryOrMyExecutable" in directory /someDirectory

VPX_LIBRARIES
linked by target "MyLibraryOrMyExecutable" in directory /someDirectory

cmake在从find_library()中读取NAMES中的vpx后查找libvpx.so,但是找到像libvpx.so.1这样的不同文件,因此我也使用了1b,我给出了确切的名称。但仍然没有运气。

Q如何解决一个像这样的一个问题,即共享对象的名称还包括扩展后一个数字,确切的名称不与find_library()给出的名称相匹配。 ?我试图给出确切的名称,这也是行不通的

命令find_library使用CMAKE_FIND_LIBRARY_SUFFIXESCMAKE_FIND_LIBRARY_PREFIXES变量来粘贴真正的库名称。例如:

> cat CMakeLists.txt 
message("suffixes: ${CMAKE_FIND_LIBRARY_SUFFIXES}") 
message("prefixes: ${CMAKE_FIND_LIBRARY_PREFIXES}") 
> cmake -H. -B_builds 
suffixes: .so;.a 
prefixes: lib 

CMAKE_FIND_LIBRARY_SUFFIXES是一个列表变量,你可以添加一个新的后缀:

> cat CMakeLists.txt 
cmake_minimum_required(VERSION 2.8) 
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.17) 
find_library(library edata-book-1.2) 
message("library: ${library}") 
> cmake -H. -B_builds 
library: /usr/lib/libedata-book-1.2.so.17 

我敢肯定的是,真正的问题这里是包管理器的使用( :通常 lib<name>.so是符号链接到lib<name>.so.N.M文件。因此,我建议您检查手册 并以适当的方式安装您的库。