I have the following direcory stucture:
src
+-- lib1
+-- lib1.h
+-- lib2
+-- lib2.h
Both lib1 and lib2 are gonna be distributed (installed). lib2 makes use of lib1, so it needs some includes:
#include "../lib1/lib1.h" // 1
#include "lib1/lib1.h" // 2
#include <lib1/lib1.h> // 3
(1) is the straight forward way, but is very unflexible. (2) is the way I use at the moment, but the build system needs to know that src needs to be added to the include path. (3) seems the best for me under the distribution aspect because then it can be assumed that the headers reside in a standard location, but it’s not too obvious for me how a build system handles that (in this case, lib1 needs to be installed before lib2 can be compiled).
What’s the recommended way?
The only difference between
""and<>forms of include is that the""forms first search in some places and then fallback to the same places as<>. The set of additional places is implementation dependent and the only common one is the directory of the file containing the include directive. The compiler options which add to the include path usually add for the<>form and so those directories get searched for both form.So the choice between the two forms is mostly a style one. Using the
""form for the current project and the<>one for system libraries is common. For things in between, made a choice and stick to it in your project.