I develop largely in java which has maven or ant/ivy. Is there a recommended way to manage build dependencies for c++ projects? I'm setting up the build on our build server right now but the thing that comes to mind is that if the dependency libraries change how do I track that so old builds are not affected but new ones can use newer versions of a library?

One simple thought is that I move all the third party libraries into my repository and then reference them with:

#include "sqlite3.h"
#include "mosquitto.h"

Instead of

#include <sqlite3.h>
#include <mosquitto.h>

Can someone recommend how to best do this in production?

  • 2
    Definitely don't change the code. Moving 3rd party libraries into your repository is fine, but change the include path to accommodate them. Nov 15, 2018 at 21:23
  • @AlexReinking when you say don't change the code, that means keep the "<sqlite3.h>?
    – simgineer
    Nov 16, 2018 at 0:14
  • Yes, that's what I mean. Nov 16, 2018 at 0:18
  • @AlexReinking May I ask how you normally organize third party libraries in a repo? Do you just stick the components into a directory called thirdparty at the root of the repo or is there a more ideal naming convention that is normally used?
    – simgineer
    Nov 16, 2018 at 1:20
  • If you look at my answer, that's what I suggest. I prefer third_party, but I've also seen thirdparty, Ext, deps, and others. Nov 16, 2018 at 1:22

1 Answer 1


Moving third party build dependencies into your repository is perfectly fine, and even has some advantages (eg. no version mismatches, tracked upgrades). But doing so should not touch your code.

C/C++ use an include path to determine where to find libraries that are included like so

#include <...>

Depending on your toolchain and build system, you'll have to follow different steps to configure this. Regardless, the best thing would be to create a "third_party" folder with subfolders containing each dependency. Then add each of those folders to your include path such that your existing include directives work.

In CMake, you should use the target_include_directories to accomplish this. In a plain Makefile with GCC or clang, you would add the -I flag for each folder.

  • If I could inquire just a little more, inside the third_party do you normally place the sqlite.h files at the root of the subdirectories "sqlite3" or "mosquitto" or is there an extra level of directories for "include" and "lib/x86_64-linux-gnu". Seems to me just the first level is sufficient?
    – simgineer
    Nov 20, 2018 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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