0

Is it possible to make g++/ld show the absolute path of the library, that a -l option has been resolved to? In my case I am trying to link the lrs library through -llrs and I suspect that it resolves to /usr/lib/liblrs.so but I want to be sure.

Urquhart
  • 129
  • 10
  • That only shows include paths, not library paths. However, a similiar method to show library paths would only list all candidates, not the actual resolution. – Urquhart Dec 04 '19 at 15:41
  • `ldd foo` shows the runtime resolution of the library, if that helps you. – Ctx Dec 04 '19 at 15:42
  • If linking using `g++` you might want to try `-Wl,--verbose` . – G.M. Dec 04 '19 at 15:43

1 Answers1

1

ELF files do not include an absolute path to the shared library. That is the job of the dynamic linker. You can confirm this by running. strings executable | grep libname. The shared library can be anywhere on the linker search path.

readelf -d executable

To test the behaviour of the dynamic loader use ldd (List Dynamic Dependencies)

Example below with /bin/bash

ldd /bin/bash

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6

You may also want to follow symlinks

ls -al /lib/x86_64-linux-gnu/libc.so.6

lrwxrwxrwx 1 root root 12 Feb 5 2019 /lib/x86_64-linux-gnu/libc.so.6 -> libc-2.23.so

Mike Seeds
  • 400
  • 3
  • 10