Whenever I start developing a new shared library in C++ I come across the same question:
Should I use includes relative to the position of the current file or includes relative to the (potential) include paths (-I
) to refer to other header files within my project, i.e. the same library?
I checked with some of the library headers installed on my system.
boost
appears to use includes relative to the include path and<>
brackets to include other boost headers, i.e.#include <boost/move/move.hpp>
poppler
on the other hand appears to use some weird relative paths with""
, sometimes relative to the current location and sometimes relative to its base (I didn't even know that this works), .e.g. infofi/FoFiEncodings.h
there is an#include "goo/gtypes.h"
wherefofi
andgoo
are directories on the same level- many others simply include files with
""
and their location relative paths, mainly files in the same directory
Does it depend on the directory structure (i.e. its complexity) of the shared library itself, i.e. location relative paths work well with simple layouts but have drawbacks with more cross references like in boost
? Are there any technical reasons or pitfalls why one might work but the other doesn't (portability, compiler dependent behavior, ...)?