I support both styles... for different uses
Let's suppose you also have a directory root/src/common
for the purpose of my example
// in src/module1/foo.cpp
#include "module1/foo.h"
#include "../common/stringProcessing.h"
Include
I prefer not to see the 'include' directory, as said of course it is thus more difficult to locate the exact header file... but when you begin and move toward multiple independent libraries you NEED to abstract because you want to be able to move the various components around without altering the code, and I am all for consistency.
Also, there is always the risk using '..' that it does not go where you thought because of a symbolic link traversed backward :/
Source
Sometimes you have headers that are not public, and thus not in the include
directory. These are usually for implementation details that are not relevant for your clients. For those I use the ..
if need be and precise the exact location.
This allows:
- not to clutter the -I
with all possible directories of src
- locate easily the file among your sources
- easily test for dependencies among your sources (grep for ..
)
Misc
If I have to type
#include "module/foo.h"
Then I expect to use:
module::Foo myClass;
which makes it easy to match one particular type to one particular module.
The requirement one library - one namespace, with identical names, makes it easy to navigate the some ~300 or ~400 components we have at work: we HAD to work out some way to organize them!
This means though that your initial layout is reworked as (for the module
project):
root
-- include
---- module
------ part1
------ part2
-- src
---- part1
---- part2
And you then use the following directive: -I/path../root/include
And I expect you to create either a libmodule.so
library or a module
binary.