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?
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– simgineer2018年11月20日 03:00:48 +00:00Commented Nov 20, 2018 at 3:00
third_party
, but I've also seenthirdparty
,Ext
,deps
, and others.