I have to admit that I feel completely lost each time I have to fulfill the dependencies of some C or C++ code. Currently, I'm on Ubuntu 9.10 (Karmic Koala), but I remember the same feeling of forlornness from Windows.

I really think that I do understand C, C++, static and dynamic libraries, header files and linking, as well as the packet manager "aptitude", but when it comes to the practical part, I have absolutely no idea what to do. Even if I manage it somehow, I don't really know how I got there and learn nothing from it.

For example, today I wanted to use code which states that "It uses glib2, curl and openssl". In the end, I figured out that curl and openssl were already installed, but I needed to install libcurl3-dev via my packet manager, which will also required (and installed) libcurl4-openssl-dev so that I didn't have to worry about OpenSSL. But I had to choose these packet names from 67 similar-sounding alternatives. And glib, on the other hand, had to be downloaded and built manually since there was no matching packet at all.

It took my several hours to find this out, and it's not the first time. So my question really is:

When I have a vague description of the dependencies:

  • How do I find out which of those are already installed?
  • How do I figure out which of those can be fulfilled by installing packages?
  • How do I know the exact names of those packages?
  • If a package has to be built from source, how do I ensure that I don't get lost in the endless dependencies of this source, and the dependencies of those dependencies...?
  • I think I also need to link the libraries with my object files. If a single packet comes with several static library files, how do I know (without trial and error) which one to link?

migrated from stackoverflow.com Feb 3 '10 at 4:42

This question came from our site for professional and enthusiast programmers.

  • This site is about programming, not sorrow. How about a more concise description of a concrete problem? – bmargulies Feb 3 '10 at 3:07
  • 1
    My initial feeling was that this was a marginal programming question but the more I thought about it I think it is useful. It is a frustration for many developers - who hasn't been shoved down the rabbit hole and spent an entire morning compiling 12 dependencies? I think the question has a wider audience than most want to admit. – Duck Feb 3 '10 at 3:37
  • This reads as a "How do I use the package manager?" question to me, and thus Super User fodder. OTOH I can see "How do I run down and install dependencies by hand?" as being more appropriate for SO, because in the absence of good documentation for each and every thing you have to get, you end up reading ./configure and make output looking for the relevant error message in the torrent... – dmckee Feb 3 '10 at 4:41
  • the development package for the glib2 library is called, believe it or not, libglib2.0-dev – user23307 Feb 3 '10 at 4:59
  • @justin: Thanks. I searched packages.debian.org for "glib" and this yielded no useful result. I didn't realize that I had to search for "glib2", and then I get "glib2.0dev" – Lena Schimmel Feb 4 '10 at 18:45

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, the openssl 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, use dpkg -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).
  • 2
    The package contents search functions at packages.debian.org are a great resource, too. – caf Feb 3 '10 at 3:33
  • 2
    add some info about "apt-file search foo.h" ... debianhelp.de/apt-file.html, otherwise your answer is pretty much complete – akira Feb 3 '10 at 7:50
  • 1
    @akira: apt-file seems to be pretty cool. I didn't know of this before, thanks a lot. You should've made this a separate answer, you would have got an upvote from me ;) – Lena Schimmel Feb 4 '10 at 18:57

Nobody mentioned

aptitude build-dep

The man-page entry is pretty comprehensive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.