如何在运行时删除 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)