What package does this file belong to?

If you're messing playing around with some code, you probably have reached that point where you copy code from a tutorial but it doesn't compile because your system is missing an include file. And you don't have a clue of where to look for it, or maybe you have a clue but the package maintainers thought of a different naming for the package and it's very different from what you suspect it is.

But lament no more, for I just found a nifty utility for Debian based systems such as Ubuntu that is proving already very useful: apt-file. And I wonder how could I survive without it before. It's very simple to use: enter apt-file search the_missing_include.h in your favourite terminal session, and it will let you know which package(s) contain that cheeky .h.

For example, I was trying to compile a basic sample snippet for testing ALSA, and it has an #include <alsa/asoundlib.h> right in the first line. I crossed my fingers and hoped for that include to be already on my system, but I got this error instead:


alsa_test.c:1:28: error: alsa/asoundlib.h: No such file or directory

Where could the file reside? I guessed it could be in alsa-dev, but apt-file quickly proved me wrong:


$ apt-file search alsa/asoundlib.h
libasound2-dev: /usr/include/alsa/asoundlib.h

So that's it, asoundlib.h is in the package libasound2-dev.

Of course, you can install apt-file with apt-get or with synaptic package manager, as you wish. This is apt-cool! :-D