Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a way to find for a given LDFLAG, like -lcryptopp, the distribution package that provides me with that that library, like libcrypto++-dev on Debian/Ubuntu.

So far, I have looked up these libraries by hand and common sense, and using e.g. aptitude search, apt-file searchand Google.

However, now I am building a VM in which I want to test-compile all Haskell community packages, and those depend on more C libraries than I can look up by hand.

How would you, somewhat reliably, look up the package by its linking name?

I'm working on Debian-based systems, but also interested in solutions for other distributions. Anything that will make this job easier is appreciated, be it a web service, some tool or database, or smart knowledge about certain files are named.

I am aware that this cannot be fully automated, since two different packages can technically provide libraries with the same name. I'm fine with something that can find most of the packages.

share|improve this question

If you have the packages installed on a system:

  for pc in $(find /usr/lib/pkgconfig/ ${PKG_CONFIG_PATH//:/ } -maxdepth 1 -name "*.pc"); do
      printf "$pc " 
      pkg-config --modversion --libs ${pp}
      printf "\n"

This calls pkg-config with every installed .pc file on your system, it queries the libraries each packages uses and the library path required (which are the -l and -L flags respectively, as passed to the compiler/linker). This is more or less what the typical configure script does (when you're off making coffee or something more productive than watching lines scroll by).

There are also likely to be a few stragglers which do not use pkg-config, and instead install a -config script:

for pkg in $(find ${PATH//:/ } -maxdepth 1 -type f -name "*-config"); do 
    printf "$pkg " 
    $pkg --version --libs
    printf "\n"

You'll still need to do a bit of grep-ing to find exactly what you're looking for, since the output of the above is what the package needs to pass to the compiler it will include the packages own dependencies too. The library/libraries that the package itself provides tend to be listed first though, e.g.

/usr/bin/xine-config 1.1.7
-L/usr/lib -lxine -lz -lresolv -lnsl -pthread -lrt
/usr/local/lib/pkgconfig/flac.pc 1.2.1
-L/usr/local/lib -lFLAC -lm  

Once you have the .pc file or the -config file identified, confirm the package with dpkg:

 dpkg -S /usr/lib/pkgconfig/libxml-2.0.pc
 libxml2-dev: /usr/lib/pkgconfig/libxml-2.0.pc

or the local package manager equivalent, e.g. rpm -q --whatprovides /usr/lib/pkgconfig/libxml-2.0.pc

share|improve this answer

You can list the packages of all installed header files by running:

find / -name '*.h' | xargs -i apt-file search {}

This will take a long time, but you'll have a complete list of all libraries installed on your system. You can also list all .h files within all packages:

apt-file search --regexp '\.h$'
share|improve this answer

You must log in to answer this question.

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