找回密码
 注册
搜索
热搜: 回贴
微赢网络技术论坛 门户 服务器 Linux/BSD 查看内容

How to specify library path in runtime

2009-12-20 13:22| 发布者: admin| 查看: 47| 评论: 0|原作者: 仙之剑缘

In Linux, we can set the environmental variable LD_LIBRARY_PATH to specify the library path for application to search the shared libraries. But in some case, we could use another method to specify the library path instead of setting the variable. The Linux ELF program loader /lib/ld-linux.so.2 could help us complete this. Just lanuch this file directly, and the output is shown as following:
$ /lib/ld-linux.so.2
Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]
You have invoked `ld.so', the helper program for shared library executables.
This program usually lives in the file `/lib/ld.so', and special directives
in executable files using ELF shared libraries tell the system's program
loader to load the helper program from this file. This helper program loads
the shared libraries needed by the program executable, prepares the program
to run, and runs it. You may invoke this helper program directly from the
command line to load and run an ELF executable file; this is like executing
that file itself, but always uses this helper program from the file you
specified, instead of the helper program file specified in the executable
file you run. This is mostly of use for maintainers to test new versions
of this helper program; chances are you did not intend to run this program.
--list list all dependencies and how they are resolved
--verify verify that given object really is a dynamically linked
object we can handle
--library-path PATH use given PATH instead of content of the environment
variable LD_LIBRARY_PATH
--inhibit-rpath LIST ignore RUNPATH and RPATH information in object names
in LIST
From the output, we can see that the option --library-path could help us specify the PATH to search shared librarys. Given that we have a binary hello, which linked a shared library libhello.so which locates in the folder /home/abc/lib, we can execute following command to launch the binary hello:
/lib/ld-linux.so.2 --library-path /lib:/usr/lib:/home/abc/lib hello





最新评论

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 03:22 , Processed in 0.124072 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部