I know how to actually do the linking, but I'm not sure what the best practice is for actually getting those libraries downloaded and into my repository. Should I just straight-out include them using Git? Should I use git submodules (but what if the library in question doesn't use git)? Or should I provide a shell script to download them before building? How is this handled in most projects?

  • 3
    There is no best practice May 7, 2017 at 6:05

2 Answers 2


Your goal should be that a new developer can get all the sources needed to build your product as easily as possible, and that you can easily get lets say a nine month old version of all sources from git and build it.

There are two ways to do this: Either you make it a part of your build process that external sources are automatically downloaded and built as needed, so if I check out nine month old sources and press the "Build" button, nine month old versions of these external sources are automatically downloaded and built as well. Or you check in those sources into your git project. Which is the easiest and most reliable method.


There is no unique answer, and it is also a matter of opinion and habits and conventions (which are probably different in various communities and for various operating systems or computers).

At the very least, document the required dependencies, what version you expect (even for build tools, e.g. your C++ compiler), and where to download them. Try to avoid, or to help against, any dependency hell.

(I am implicitly thinking of some free software for GNU/Linux; adapt my hints to your system & communities)

If your program is some free software running on Linux, and if the dependencies are common free software (e.g. libcurl and zlib are probably packaged in every Linux distribution), you could just mention them.

You may also want to package your software for some common Linux distributions. You could even provide for downloading a .deb and/or .rpm package file of your software. You may hope that distribution contributors might package your free software.

BTW, I recommend against static linking and strongly suggest to dynamically link (at least against common libraries).

If the dependencies are some uncommon libraries (not often packaged) you could use a git submodule

Some software projects provide a script to download and/or build dependencies. For example, GCC provides a contrib/download_prerequisites script.

If possible, explain what to do when dependencies are updated (e.g. when the libcurl dependency goes from version 7.50 to 7.52) and how to rebuild your stuff. Try to facilitate the case when a dependency is installed in some non-standard way (e.g. a newer version in /usr/local/lib/ with the older system version in /usr/lib/). Perhaps tools like autoconf or cmake or pkg-config might be relevant to deal with this. At least, have readable and easily improvable build procedures (for example, have a nicely commented and well written Makefile and use appropriate variables there)

BTW, I believe that practices are wildly different on Linux, on MacOSX, on Android, on Windows or even between different communities (e.g. web server administrators vs nuclear physicists or bioinformatists).

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.