如何在运行时删除 LD_LIBRARY_PATH?

发布于 2024-08-26 03:19:20 字数 1050 浏览 6 评论 0原文

我正在构建一个使用英特尔的 IPP 库的 C++ 应用程序。该库默认安装在 /opt 中,并要求您设置 LD_LIBRARY_PATH 来编译和运行软件(如果您选择共享库链接,我就是这么做的)。我已经修改了 configure.ac/Makefile.am ,这样我在编译时就不需要设置该变量,但在运行时我仍然找不到共享库-时间;我该怎么做?

使用 -Wl, -R/path/to/libdir 标志进行编译

我正在使用 g++ Update 1 : 实际上我的二进制程序有一些正确链接的 IPP 库,但只有一个没有:

$ ldd myprogram
linux-vdso.so.1 =>  (0x00007fffa93ff000)
libippacem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippacem64t.so.6.0 (0x00007f22c2fa3000)
libippsem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippsem64t.so.6.0 (0x00007f22c2d20000)
libippcoreem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippcoreem64t.so.6.0 (0x00007f22c2c14000)
[...]
libiomp5.so => not found
libiomp5.so => not found
libiomp5.so => not found

当然该库在那里:

$ locate libiomp5.so
/opt/intel/ipp/6.0.2.076/em64t/sharedlib/libiomp5.so

I am building a C++ application that uses Intel's IPP library. This library is installed by default in /opt and requires you to set LD_LIBRARY_PATH both for compiling and for running your software (if you choose the shared library linking, which I did). I already modified my configure.ac/Makefile.am so that I do not need to set that variable when compiling, but I still can't find the shared library at run-time; how do I do that?

I'm compiling with the -Wl, -R/path/to/libdir flag using g++

Update 1:
Actually my binary program has some IPP libraries correctly linked, but just one is not:

$ ldd myprogram
linux-vdso.so.1 =>  (0x00007fffa93ff000)
libippacem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippacem64t.so.6.0 (0x00007f22c2fa3000)
libippsem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippsem64t.so.6.0 (0x00007f22c2d20000)
libippcoreem64t.so.6.0 => /opt/intel/ipp/6.0.2.076/em64t/sharedlib/libippcoreem64t.so.6.0 (0x00007f22c2c14000)
[...]
libiomp5.so => not found
libiomp5.so => not found
libiomp5.so => not found

Of course the library is there:

$ locate libiomp5.so
/opt/intel/ipp/6.0.2.076/em64t/sharedlib/libiomp5.so

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

罪歌 2024-09-02 03:19:20

通过 /path/to/lib 您的意思是包含库的目录的路径,还是实际文件的路径?

给定目录参数的 -R 选项被 ld 处理得像 -rpath 一样,这是您真正想要的选项。它将给定目录添加到运行时库搜索路径。只要您给它目录而不是文件名,这应该可以工作。我对此相当有信心,因为我自己做过,并且因为这是 libtool 给出的提示之一:

库已安装在:

/路径/到/库目录

如果您碰巧想要链接已安装的库
在给定目录 LIBDIR 中,您必须使用 libtool,并且
指定库的完整路径名,或使用“-LLIBDIR”
在链接期间标记并至少执行以下操作之一:

  • 将 LIBDIR 添加到“LD_LIBRARY_PATH”环境变量
    执行期间
  • 将 LIBDIR 添加到“LD_RUN_PATH”环境变量
    链接期间
  • 使用“-Wl,-rpath -Wl,LIBDIR”链接器标志
  • 让您的系统管理员将 LIBDIR 添加到“/etc/ld.so.conf”

(我将其粘贴到此处,因为可以想象其他选项之一可能更理想) - 例如LD_RUN_PATH可以节省你对makefile的修改)

By /path/to/lib do you mean path to the directory containing the library, or the path to the actual file?

The -R option given a directory argument is treated like -rpath by ld, which is the option you're actually wanting here. It adds the given directory to the runtime library search path. That should work, as long as you give it the directory and not filename. I'm fairly confident about that, having done it myself, and because it's one of the hints given by libtool:

Libraries have been installed in:

/path/to/library-directory

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:

  • add LIBDIR to the `LD_LIBRARY_PATH' environment variable
    during execution
  • add LIBDIR to the `LD_RUN_PATH' environment variable
    during linking
  • use the `-Wl,-rpath -Wl,LIBDIR' linker flag
  • have your system administrator add LIBDIR to `/etc/ld.so.conf'

(I paste this here since conceivably one of the other options could be more desirable - for example LD_RUN_PATH can save you makefile modification)

夜唯美灬不弃 2024-09-02 03:19:20

正如 Richard Pennington 所建议的,缺少的库不是由我的应用程序直接使用的,而是由我使用的共享库使用的。由于我无法重新编译 IPP,因此问题的解决方案是在编译时添加 -liomp5,使用链接器的 -R 选项。这实际上添加了 libiomp5.so 的 rpath 来解决问题!

As suggested by Richard Pennington, the missing library is not used directly by my application, but it is used by the shared libraries I use. Since I cannot recompile IPP, the solution to my problem is to add -liomp5 when compiling, using the -R option for the linker. This actually adds the rpath for libiomp5.so fixing the problem!

雪若未夕 2024-09-02 03:19:20

您可以通过在您的计算机上运行 ldd 命令或 readelf 命令来检查是否从 -R 标志中获取了库的路径。二进制。 LD_LIBRARY_PATH 环境变量是一个覆盖变量,因此通常不需要。

You can check if the path to the library is being picked up from your -R flag by running the ldd command or the readelf command on your binary. The LD_LIBRARY_PATH environment variable is an override, so shouldn't be necessary normally.

残月升风 2024-09-02 03:19:20

如果可能,您应该使用 -R 选项。

如果没有,请重命名您的可执行文件并创建一个运行您的可执行文件的启动脚本,并在其中仅针对该范围设置 LD_LIBRARY_PATH。

根据平台的不同,您可以通过 /etc/ld.so.conf.d(例如 Redhat/Fedora)修改 ld.so.conf,这使得从部署场景中部署对 ld.so 的更改变得“更容易”。

You should use the -R option if possible.

If not, rename your executable and create a launch script that runs your executable, and in there set LD_LIBRARY_PATH just for that scope.

Depending on platform, you can modify ld.so.conf via /etc/ld.so.conf.d (Redhat/Fedora come to mind) which makes deploying changes to ld.so "easier" from a deployment scenario.

分分钟 2024-09-02 03:19:20

除了此处发布的所有有用提示之外...您不会尝试在 32 位系统上使用 64 位特定库(反之亦然,具体取决于其他条件),是吗?

Besides all the useful hints posted here.. you're not trying to use a 64-bit specific library on a 32-bit system (or viceversa, depending on other conditions), are you?

葬花如无物 2024-09-02 03:19:20

bash:

export LD_LIBRARY_PATH=/path/to/lib

tcsh:

setenv LD_LIBRARY_PATH /path/to/lib

bash:

export LD_LIBRARY_PATH=/path/to/lib

tcsh:

setenv LD_LIBRARY_PATH /path/to/lib
一曲琵琶半遮面シ 2024-09-02 03:19:20

尝试通过 ld.so 配置您的 ldconfig .conf 因此它默认搜索您的 /opt/... 目录。

Try configuring your ldconfig through ld.so.conf so it searches your /opt/... directory by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文