Chinaunix首页 | 论坛 | 博客
  • 博客访问: 217093
  • 博文数量: 20
  • 博客积分: 2016
  • 博客等级: 大尉
  • 技术积分: 660
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-16 00:15
文章分类

全部博文(20)

文章存档

2010年(1)

2008年(19)

我的朋友

分类: LINUX

2008-09-12 12:28:15

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

阅读(927) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~