Project file tree

Are there any articles or guidelines for organizing a file hierarchy in your project? I'm interested in how to name folders, split sources and headers or not.

I have a project written in C ++, a library and a project using it. The library has many components, they are separated from each other, but some of them use common files. Should I create directories for them?

I will be glad to hear all the recommendations.

+4
source share
3 answers

It’s good to keep the namespace in separate folders. Nest namespaces are the same as they are nested in your project. For example, if you have:

namespace Foo{ namespace Bar{ } } 

then you want any objects in the Bar namespace to be in

{Foo parent folder}\Foo\Bar\{how you're organizing code at this level}

We use the include folder for headers, the source for .cpp, the test folder for unit tests, and the object folder for compiled code bits. The reason we separate them is to simplify the batch code in our scripts. You will always go around the headlines; you will not go around the source. ( Here is another SO thread discussing the separation of header / source files. This is the preferred thing.)

Below is a link to google style guides if that helps.

+3
source

Do not separate the headers and source files into separate folders. This is nothing more than adding an extra folder level.

At best, this is completely useless; if you are looking for "widget.h", you can trivially find it, even if there is "widget.cpp" next to it. In the worst case, it is rather counterproductive - for example, when you edit "widget.h" and find that you also need to update "widget.cpp".

+6
source
  • I do not share the headings from the source: it is a pain to view
  • Subdirectories generally match my namespaces

     + Project root + <project_name> // namespace project - sub_dir_1 // namespace project::sub_dir_1 - sub_dir_2 // namespace project::sub_dir_2 
  • I add only the "project root" as an optional include path, so it includes the form:

     #include "project/sub_dir_1/ah" #include "project/sub_dir_2/bh" 
  • Since the source and header are usually named according to the class they contain, all qualified named ones can be inferred from the include path:

    project::sub_dir_1::a is located in project/sub_dir_1/ah

  • ac trivially includes ah (relative path provided)

  • If I have to include ah from bh , I use the absolute path (starting from the root of project/ )
+2
source

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


All Articles