Installing libraries and header files under Ubuntu Linux for C/C++ development
Figuring out which packages to install to satisfy dependencies is not an exact science. But there are some tips that might help you:
- When you're working with satisfying dependencies to compile something, you nearly always want the package that ends in
-dev
. This is short for development. For example, theopenssl
package contains command line tools and libraries for working with encryption.libssl-dev
contains header files and libraries for openssl development. - To search for a package by keyword using apt, use
apt-cache search
. For example, I didn't actually know that libssl-dev was what the name of the openssl dev package was. I found that using this command:apt-cache search openssl | grep dev
and then going with the one that didn't seem to be related to another language/library. - You can see what packages you have installed using
dpkg -l
, but, in general, just find the package you want and tell apt to install it, if you already have it then apt will tell you. Another good tip is if you want to know what package owns a file, usedpkg -S /path/to/thefile
- If you end up needing to build a package from source, there's no easy way to resolve the dependency tree.
./configure
should tell you, or the README file. Often they will even name the exact package required. - For figuring out what to link, usually that's related to the name of the package or the most general name for what you want. For our libssl example, you would just pass
-lssl
to gcc. If you don't know what the options for-l
are, take a look in /lib/ (just remove the "lib" from the front and the ".so..." from the back to get the 'middle' which is passed to gcc).
Nobody mentioned
aptitude build-dep
The man-page entry is pretty comprehensive.