How to organize a C++ project

paxilpaz picture paxilpaz · May 28, 2012 · Viewed 8.1k times · Source

I would like to know what are C++ best practices when it comes to organizing my project. I've read that I should put all the source files (.cpp) in the src folder and header files (.h) should be placed in the include folder. Is it the way it is supposed to be, or should I put my header files in the source files folder?

This is my folder tree structure

- Project
|
+--- src (.cpp)
|
+--- include (.h) ????
|
+--- test (cpp unit test)
|
+--- doc (docs)

Answer

Alok Save picture Alok Save · May 28, 2012

It is a matter of preference really but organization of a code base helps for maintainability as well as for easily understanding the code. One should have an Modular approach as much as possible. Your code organization just looks about almost right, Ideally I would have:

- Project
|
+--- src (.cpp)
|
+--- include (.h) ????
|
+--- test (cpp unit test)
|
+--- doc (docs)
|
+--- bin (generated binaries)
|
+--- lib (external dependencies)