简体   繁体   English

可执行文件在生成后缺少完整的库路径

[英]Executable missing full library path after build

I am using CMake to compile an executable that is linked against several libraries that I have built and installed into a local project directory (libs/3rdparty). 我正在使用CMake编译一个可执行文件,该可执行文件与我已构建并安装到本地项目目录(libs / 3rdparty)中的几个库链接。 Note that this is prior to installation of the project, primarily for the purpose of running unit tests and debugging. 请注意,这是在安装项目之前进行的,主要是为了运行单元测试和调试。 The problem I am having is that sometimes there is a library that is linked, but the executable is missing the path to the library. 我遇到的问题是,有时有一个链接的库,但是可执行文件缺少该库的路径。 The library I am currently having an issue with is leptonica. 我目前遇到的图书馆是leptonica。 However, I have run into this issue several times with different libraries on different platforms (osx, fedora, centos, ubuntu). 但是,我在不同平台(osx,fedora,centos,ubuntu)上的不同库中多次遇到此问题。 Through research I have seen similar issues, but I have never been able to find a definitive answer of why the full path to the library would be missing. 通过研究,我看到了类似的问题,但是我始终无法找到关于为什么缺少通往图书馆的完整路径的明确答案。

I've tried playing with: 我试着玩:

CMAKE_BUILD_WITH_INSTALL_RPATH
CMAKE_INSTALL_RPATH
CMAKE_INSTALL_RPATH_USE_LINK_PATH

and these don't seem to have much effect. 而且这些似乎没有太大作用。

My CMakeLists contains: 我的CMakeLists包含:

find_package(Leptonica REQUIRED)

target_link_libraries(${target}
    PRIVATE
        ...
        ${Leptonica_LIBRARIES}
)

Here is the output from ldd on one of the unit test executables: 这是其中一个单元测试可执行文件中ldd的输出:

ldd test_utilities
...
libleptonica.so.5.3.0 => not found
libtesseract.so.4 => {MY PROJECT}/libs/3rdparty/tesseract/lib/libtesseract.so.4

leptonica is the only library that is not found out of ~30 other libraries. Leptonica是在约30个其他库中找不到的唯一库。

Does anyone know what the root cause of this problem is? 有谁知道这个问题的根本原因是什么? I am not looking to work around the problem by modifying LD_LIBRARY_PATH. 我不想通过修改LD_LIBRARY_PATH解决此问题。

-- Added LeptonicaTargets-release.cmake. -添加了LeptonicaTargets-release.cmake。 According to this the full path to the lib should be in the target. 因此,lib的完整路径应该在目标中。

#----------------------------------------------------------------
# Generated CMake target import file for configuration "RELEASE".
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Import target "leptonica" for configuration "RELEASE"
set_property(TARGET leptonica APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(leptonica PROPERTIES
  IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE "/usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libz.so;m"
  IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/libleptonica.so.1.77.0"
  IMPORTED_SONAME_RELEASE "libleptonica.so.5.3.0"
  )

list(APPEND _IMPORT_CHECK_TARGETS leptonica )
list(APPEND _IMPORT_CHECK_FILES_FOR_leptonica "${_IMPORT_PREFIX}/lib/libleptonica.so.1.77.0" )

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)

Here are the files in the leptonica/lib directory: 这是leptonica / lib目录中的文件:

ll libs/3rdparty/leptonica/lib/ 
total 2776
drwxr-xr-x 3 user user    4096 May 30 14:17 ./
drwxr-xr-x 5 user user    4096 May 30 14:17 ../
lrwxrwxrwx 1 user user      21 May 30 14:17 libleptonica.so -> libleptonica.so.5.3.0
-rw-r--r-- 1 user user 2829784 May 30 09:49 libleptonica.so.1.77.0
lrwxrwxrwx 1 user user      22 May 30 14:17 libleptonica.so.5.3.0 -> libleptonica.so.1.77.0
drwxr-xr-x 2 user user    4096 May 30 14:17 pkgconfig/

Output from chrpath --list test_utilities appears to contain the correct path to the library as well: 来自chrpath --list test_utilities的输出似乎也包含该库的正确路径:

chrpath --list test_utilities
test_utilities: RUNPATH=...:{MY PROJECT}/libs/3rdparty/leptonica/lib:...

For anyone who runs across this, I have finally figured it out. 对于遇到此问题的任何人,我都终于明白了。

The issue was related to the library being a transitive dependency of OpenCV. 该问题与库是OpenCV的传递依赖项有关。 On Ubuntu, ld now defaults to using using --enable-new-dtags which uses RUNPATH, not RPATH. 在Ubuntu上,ld现在默认使用--enable-new-dtags,它使用RUNPATH,而不是RPATH。 There is an issue where RUNPATH is not searched for transitive dependencies. 存在一个问题,其中未在RUNPATH中搜索传递依赖项。

See https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/1253638 参见https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/1253638

Simply adding "-Wl,--disable-new-dtags" to the target linker options resolved my issue. 只需在目标链接器选项中添加“ -Wl,-disable-new-dtags”即可解决我的问题。 All libraries are now found, including other libraries than leptonica that I added today. 现在可以找到所有库,包括我今天添加的leptonica以外的其他库。 I am sure that I will likely have to make changes when building a package for installation though. 我确信在构建要安装的软件包时,我可能必须进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM