简体   繁体   English

LD_LIBRARY_PATH在LD_PRELOAD正常工作时无法正常工作

[英]LD_LIBRARY_PATH not working while LD_PRELOAD works fine

I am compiling a program on one machine and running it on another one which does not have compatible libstdc++ library. 我正在一台机器上编译一个程序,并在另一台没有兼容libstdc ++库的机器上运行它。 If I run it like this, that is using LD_PRELOAD, it runs fine. 如果我像这样运行它,那就是使用LD_PRELOAD,它运行正常。

LD_PRELOAD=./libstdc++.so.6 ./program args

However, If I try to use LD_LIBRARY_PATH, like shown below, it doesn't load the library and I get the error that I don't have the required libstdc++ version. 但是,如果我尝试使用LD_LIBRARY_PATH,如下所示,它不会加载库,我得到的错误是我没有所需的libstdc ++版本。

export LD_LIBRARY_PATH="./libstdc++.so.6"
./program args

How can I solve this problem? 我怎么解决这个问题?

LD_LIBRARY_PATH , like PATH , takes a list of directories, not files. PATH一样, LD_LIBRARY_PATH获取目录列表,而不是文件。

If you want to put the current directory ( not recommended) in there, you can: 如果要将当前目录( 推荐)放在那里,您可以:

export LD_LIBRARY_PATH=.

But it is always better to put absolute paths in there so that you don't pick up random garbage if you change directories. 但是最好将绝对路径放在那里,以便在更改目录时不会随机拾取垃圾。

For your specific problem, keeping LD_PRELOAD might actually be the best way to do it in case your executable has rpath settings (which might override the environment). 对于您的特定问题,保留LD_PRELOAD可能实际上是最好的方法,以防您的可执行文件具有rpath设置(可能会覆盖环境)。 Create a wrapper script that does it if you don't want to re-type it every time. 如果您不想每次都重新键入它,请创建一个包装器脚本。

您需要在LD_LIBRARY_PATH变量中提供路径:

LD_LIBRARY_PATH=$PWD ./program args

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

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