如何在运行时删除 LD_LIBRARY_PATH?
我正在构建一个使用英特尔的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
通过
/path/to/lib
您的意思是包含库的目录的路径,还是实际文件的路径?给定目录参数的
-R
选项被 ld 处理得像-rpath
一样,这是您真正想要的选项。它将给定目录添加到运行时库搜索路径。只要您给它目录而不是文件名,这应该可以工作。我对此相当有信心,因为我自己做过,并且因为这是 libtool 给出的提示之一:(我将其粘贴到此处,因为可以想象其他选项之一可能更理想) - 例如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:(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)
正如 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!您可以通过在您的计算机上运行
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 theldd
command or thereadelf
command on your binary. TheLD_LIBRARY_PATH
environment variable is an override, so shouldn't be necessary normally.如果可能,您应该使用 -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.
除了此处发布的所有有用提示之外...您不会尝试在 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?
bash:
tcsh:
bash:
tcsh:
尝试通过 ld.so 配置您的
ldconfig
.conf 因此它默认搜索您的/opt/...
目录。Try configuring your
ldconfig
throughld.so.conf
so it searches your/opt/...
directory by default.