2

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?

asked Nov 15, 2018 at 19:51
6
  • 2
    Definitely don't change the code. Moving 3rd party libraries into your repository is fine, but change the include path to accommodate them. Commented Nov 15, 2018 at 21:23
  • @AlexReinking when you say don't change the code, that means keep the "<sqlite3.h>? Commented Nov 16, 2018 at 0:14
  • Yes, that's what I mean. Commented 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? Commented 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. Commented Nov 16, 2018 at 1:22

1 Answer 1

3

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.

answered Nov 16, 2018 at 0:27
1
  • 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? Commented Nov 20, 2018 at 3:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.