Search code examples
compilationlinkershared-librariespkg-config

How are you supposed to know what library names are


When using a tool like pkg-config (see here), how is one supposed to know what the library name should be? It is not always intuitive. DLIB, for example, doesn't work for

  • pkg-config --cflags dlib
  • pkg-config --cflags libdlib
  • pkg-config --cflags dlib-19.9

I usually have to issue a command like sudo ldconfig -p | grep dlib, but all that does is return libdlib.so, which also doesn't work.

How do experts tackle this problem. Do they simply know all the library names?


Solution

  • It is called package name what you are using as a main parameter for pkg-config, and then applying --cflags or --libs, etc one just accesses the parameters specified and evaluated from the corresponding package config file ([some_package_name].pc, a.k.a pkg-config metadata file) that was found in pkg-config search paths.

    And yes, there is no rule how package name relates to library name. Typically it's either library name without lib- prefix or just the whole library name. I found the following in pkg-config guide:

    A common choice is to match the library name to the .pc name. For instance, a package installing libfoo.so would have a corresponding libfoo.pc file containing the pkg-config metadata. This choice is not necessary; the .pc file should simply be a unique identifier for your library. Following the above example, foo.pc or foolib.pc would probably work just as well.

    However, you can list all available in pkg-config search paths and find out the correct names before using them in Makefile:

    $ pkg-config --list-all | grep dlib