如何从 bash 更改二进制文件的库包含路径?
我在 Kubuntu 上正确安装了一个软件。
现在,我正在修补和测试它的一些库。
如何从 bash 启动软件,以便加载我的修补库而不是官方库?
例如:
官方库位于 /usr/lib/
我的补丁库(在测试开发期间使用)位于 /home/user/dev/lib/
我尝试过:
$ set LD_LIBRARY_PATH=/home/user/dev/lib/
$ binary_app &
但无济于事。
我更喜欢可以从 bash 设置的解决方案,但如果不可能,我也可以修改这个 C++ 软件的 cmake 文件。
目的是让我可以使用普通库或我修补的库轻松启动应用程序以查看差异。
编辑:它是一个 KDE .so 文件
我正在测试的库是 KDE4 库。官方库位于 /usr/lib/kde4/ 。在该目录中,没有任何库以 lib 前缀开头。
我是否这样做:
/lib/ld-linux-x86-64.so.2 --list --library-path PATH EXEC
或者
ldd EXEC
图书馆根本没有列出。
另一方面,如果将原始库移离 /usr/lib/kde4/,应用程序会启动,但相应的功能会丢失。
KDE4 库是否以特定方式加载?也许要设置的变量不同...
编辑2
所有答案都很好并且有用...不幸的是,事实证明问题似乎与lib路径设置无关。我正在处理插件架构,.so 加载路径似乎是硬编码在应用程序中的某处。我需要花更多的时间在源代码中来理解正在发生的事情......谢谢大家,+1。
I have a software properly installed on Kubuntu.
Now, I am patching and testing some of its libraries.
How can I start the software from bash so that it loads my patched libraries instead of the official libs?
e.g.:
the official libs are locate in /usr/lib/
my patch libraries (used during test development) are in /home/user/dev/lib/
I tried:
$ set LD_LIBRARY_PATH=/home/user/dev/lib/
$ binary_app &
but to no avail.
I'd prefer a solution that can be set from the bash, but if it's not possible, I could also modify the cmake file of this C++ software.
The aim is to allow me to easily start the application either with the vanilla libs, or with my patched libs to see the differences.
Edit: it's a KDE .so file
The library I am testing is a KDE4 library. The official lib is in /usr/lib/kde4/ . In that directory, none of the library start with the lib prefix.
Whether I do:
/lib/ld-linux-x86-64.so.2 --list --library-path PATH EXEC
or
ldd EXEC
The library is not listed at all.
On the other hand, if if move the original library away from /usr/lib/kde4/, the application starts but the corresponding functionality is missing.
Are KDE4 libraries loaded in a specific way? Maybe the variable to set is different...
Edit 2
All the answers are good and useful... unfortunately, it turned out that the problem does not appear to be related to the lib path setting. I'm dealing with a plugin architecture and the .so loading path appears to be hard-coded somewhere in the application. I need to spend more time within the source code to understand what's happening... Thanks and +1 to all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
来自“男人狂欢”:
如果要让您执行的程序看到变量,您需要“导出”变量。
不过,您也可以尝试以下操作:
请参阅 http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
From 'man bash':
You need to 'export' a variable if it is to be seen by programs you execute.
However, you can also try the following:
See http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
尝试使用
export LD_LIBRARY_PATH=...
而不是 set。Try
export LD_LIBRARY_PATH=...
instead of set.我已经将其放在评论中,但经过思考,我认为执行此操作的最佳方法(仅使用不同的库进行测试/调试)是使用
LD_PRELOAD
,请参阅 LD_PRELOAD 技巧是什么?从手册页:
更新:
更新问题后,应用程序似乎正在使用 dlopen 来使用绝对路径打开库。我认为你对此无能为力。请参阅
man dlopen
更新 2:
也许您可以做一些事情:您可以
LD_PRELOAD
您自己的dlopen
函数,该函数会修改您的路径自己的图书馆...I already put this in a comment but after thinking about it I think the best way to do this (using a different library just for testing/debugging) is using
LD_PRELOAD
, see What is the LD_PRELOAD trick?From the man page:
Update:
After the updated question it seems the application is using
dlopen
to open the library using a absolute path. I don't think you can do anything about it. Seeman dlopen
Update2:
Maybe there is something you can do: you might be able to
LD_PRELOAD
your owndlopen
function which modifies the path to your own library...你的应用程序 setuid 或 setgid 不是偶然的吗?在这种情况下,LD_LIBRARY_PATH 将被忽略。
Isn't you app setuid or setgid by chance? In this case LD_LIBRARY_PATH will be ignored.
将所有内容放在一行上:
Put everything on one line: