简体   繁体   English

共享库依赖于具有硬编码路径的其他库

[英]shared library depends on other libraries with hardcoded paths

I'm building opencv but some of the so libraries contain dependencies on other shared libraries whose name contains path elements ../../lib which would cause loading of libraries to fail at runtime.我正在构建 opencv,但其中一些库包含对名称包含路径元素../../lib其他共享库的依赖,这会导致库加载在运行时失败。

I've tried to change the build options and have searched online to find out how the problem happened but could not find an answer.我尝试更改构建选项并在线搜索以了解问题是如何发生的,但找不到答案。

How those path elements have been included in those .so files, and how they can be excluded?这些路径元素如何包含在这些 .so 文件中,以及如何排除它们?

As an example, below it shows one library libopencv_calibd3d.so depends on ../../lib/libopencv_features2d.so .例如,下面显示了一个库libopencv_calibd3d.so依赖于../../lib/libopencv_features2d.so I'd like those ../../lib/ to be removed from the output of the command:我希望从命令的输出中删除那些../../lib/

~sample/opencv/test$ objdump -p libopencv_calib3d.so | grep NEEDED
  NEEDED               ../../lib/libopencv_features2d.so
  NEEDED               ../../lib/libopencv_flann.so
  NEEDED               ../../lib/libopencv_highgui.so
  NEEDED               ../../lib/libopencv_imgproc.so
  NEEDED               ../../lib/libopencv_core.so
  NEEDED               libstdc++.so.6
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libc.so.6

Based on reading of the another question for shared library without hardcoding full dependency path , there are two ways to get paths encoded:基于对共享库没有硬编码完整依赖路径另一个问题的阅读,有两种方法可以对路径进行编码:

  • Using -Wl,-rpath.... .使用-Wl,-rpath.... Somehow you need to remove this.不知何故,你需要删除它。
  • Using like "~/deps/A/lib/libA.so" to link if libA.so doesn't have a SONAME .如果libA.so没有SONAME则使用类似"~/deps/A/lib/libA.so"进行链接。 You need to set a SONAME to libA.so .您需要将SONAME设置为libA.so

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

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