Using the project directory in include filename

I only develop the C ++ headers library, and I will let it PROJ. When the library header includes another, it uses:

#include <proj/foo.h> 

And the compiler (gcc and clang) has -I path-to-proj-parent . Library users must also have a PROJ parent in their include search path.

My rational use of this scheme is that after installing this library in the proj subdirectory of the parent with the default ( /usr/include/proj or /usr/local/include/proj ), the library user does not need to specify the -I option.

Are there any flaws in this scheme? Does <foo.h> without proj/ prefix use the more common and recommended way?

The question is not whether the installation in subdir or not (there will be proj subdir), but rather how to link to include files.

+4
source share
2 answers

If you look at the increase, you will notice that they use a similar scheme:

 #include <boost/shared_ptr.hpp> 

This has the advantage of preventing collisions with another similarly named file from another dependency.

However, in case of increase, they do it one more step. If you include <x/y/z.hpp> , then you are likely to be dealing with an entity with the name ::x::y::z (whether it be a function or a class). That is, the path that directories lay out in the project mimics the organization of the namespace. It is pretty neat to navigate.

As a rule, most projects are hidden in subdirectories (and subspaces), but the most convenient ones are used in the boost namespace, and therefore they have headers that live directly in the boost folder. There are also some convenience headers (whose task is to collect a small number of other headers to pull them out right away).

Finally, you may notice that if you open the header file than the ones they use, follow the same hierarchy :

 #ifndef BOOST_SHARED_PTR_HPP_INCLUDED 

again, because it helps to avoid collisions, since it is named after the file itself, and there can be only one in this place in the entire Boost project (in the case of case-sensitive file systems).

+3
source

You can have proj along the way if you create the proj directory during installation. This is actually a good way to prevent name clashes with other included files.

The name should not be something common, for example, "proj". It should be specific to the project.

+2
source

Source: https://habr.com/ru/post/1446649/


All Articles