开发者

Linking - which library is included?

The gcc man page says, "Order does matter when you use several options of the same kind; for example, if you specify -L more than once, the directories are searched in the order specified.开发者_C百科"

However, are these -L directories searched before the system directories (e.g., those that ld normally uses)?

I have the case that I have two libraries of the same name, one in a system location and another in my working directory, and I want to use mine, but cannot figure out how to verify my version is being used.


Try "ldd /bin/your/application". E.g:

ldd `which bash`
linux-vdso.so.1 =>  (0x00007fff46eda000)
libncurses.so.5 => /lib/libncurses.so.5 (0x00007facdd618000)
libdl.so.2 => /lib/libdl.so.2 (0x00007facdd414000)
libc.so.6 => /lib/libc.so.6 (0x00007facdd090000)
/lib64/ld-linux-x86-64.so.2 (0x00007facdd863000)

In general there are 3 options how one can specify which library to use for your binary:

  1. Setting LD_LIBRARY_PATH environment variable before starting your executable
  2. RPATH linker option (see other my questions/answers on SO to find out more about this option)
  3. Add your shared library to all other system libraries.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜