Search code examples
c++headerinclude-path

How to namespace C++ header files?


I use a code with different libraries, which use names like defines.h. This does not only cause conflicts for identical filenames, but also creates confusion. From which library is the defines.h include?

Including as #include <library/defines.h> would be a clean solution, but then the include path would need to be the parent directory of the library, which is rather unclean again. Is there some way to alias the include path, so that -I/path/to/library makes the headers available under library/headername.h?


Solution

  • Is there some way to alias the include path, so that -I/path/to/library makes the headers available under library/headername.h?

    There seems to be no need to in this case. You can simply use -I/path/to which makes /path/to/library/headername.h available under library/headername.h.

    That said, while there is no such compilation option (that I know of), you can create such "aliases" to file paths in most file systems. These aliases are called symbolic links. In this case, you could make a link /path/to/library/mylibrary that points to . which would make /path/to/library/headername.h available under mylibrary/headername.h assuming you've used -I/path/to/library.