.so with numerals after that, how to match them in find_library in cmake ? Error in linking shared objects which are found as sub-dependencies

喜欢而已 提交于 2019-12-10 10:36:11

问题


Given
ls -lrt /usr/lib/libvpx* results

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* results

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* results

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

This is a possible solution to issues found in Approach 1 of this question. You may/ may not refer that.

Possible Solution
As I mentioned in the parent question, we may need to add three find_library() functions. Below are contents from CMakeLists.txt

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

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

Error
I get the same error for both the solutions 1a and 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 looks for libvpx.so after reading vpx in NAMES from find_library(), but find a different file like libvpx.so.1 hence I used 1b too where I have given the exact names. But still no luck.

Q How do one resolve an issue like this where the name of the shared objects also include a number after the extension, and the exact name does not match with the name given in find_library(). ? I tried to give the exact names, that also does not work


回答1:


Command find_library use CMAKE_FIND_LIBRARY_SUFFIXES and CMAKE_FIND_LIBRARY_PREFIXES variables to glue the real library name. For instance:

> 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 is a list variable and you can add a new suffix:

> 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

But I'm pretty sure that the real problem here is package manager usage (: Usually lib<name>.so is a symlink to lib<name>.so.N.M file. So I recommend you to check manuals and install your library in an appropriate way.



来源:https://stackoverflow.com/questions/17880532/so-with-numerals-after-that-how-to-match-them-in-find-library-in-cmake-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!