3

Suppose using the pkg-config I can find which link flags are needed add a library to my code, suppose if I need cairo libraries to add, I can find the appropriate -l flag by

> pkg-config --libs cairo
> -lcairo

How do I find the reverse (i.e. link flags --> library name)? Suppose I want to know which library will be added by invoking -lm flag, how do I do that?

1 Answer 1

1

Suppose I want to know which library will be added by invoking -lm flag, how do I do that?

The part after the -l is the name of the library. Its binary is prefixed with lib, so you can find them by that name;

> whereis libm
libm: /usr/lib64/libm.a /usr/lib64/libm.so

> whereis libcairo
libcairo: /usr/lib64/libcairo.so

Etc.

If whereis does not say anything, you can also try grepping the output of ldconfig -p (see man ldconfig):

> ldconfig -p | grep "libm.so"
    libm.so.6 (libc6,x86-64, OS ABI: Linux 2.6.32) => /lib64/libm.so.6
    libm.so.6 (libc6, OS ABI: Linux 2.6.32) => /lib/libm.so.6
    libm.so (libc6,x86-64, OS ABI: Linux 2.6.32) => /lib64/libm.so

Notice in this case I've appended "libm" with ".so", which is not necessary, but it saves matching against "libmfoo...", "libmbar...", etc. Since -l refers to linking shared object (.so) libraries, this should be pretty foolproof.

3
  • thanks for the pointer, in my machine the whereis command does not give anything. Anyway I am managing it with the locate command for the time being.
    – ramgorur
    Mar 31, 2014 at 22:18
  • Yes, whereis is not really intended for finding (shared) libraries, although it generally does work and the usage and output are simple. For cases where it doesn't I've added a paragraph above about grepping ldconfig -p instead.
    – goldilocks
    Apr 1, 2014 at 3:09
  • If you don't know whether the library is installed, apt-file search is better. Apr 1, 2014 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .