1

What is the best or most commonly used practice for the folder structure of a project:

project |-- src |-- include

or

project |--src
              |--include

i.e. have the include folder within the source folder or both next to each other?

edit:

This wuestion is similar: Separate "include" and "src" folders for application-level code? , but the answers are not really satisfying.

Community
  • 1
  • 1
steffen
  • 8,572
  • 11
  • 52
  • 90
  • I believe the second is more common, where `include` contains only externally visible header files (like those that get distributed with a library, for example). Other header files go inside `src` along with the rest of the source code. – Joseph Mansfield Feb 19 '14 at 13:08
  • I always put the include files in the same directory as the source to which they relate, and use folders to segregate different bits of the application (usually separate DLLs). But of course putting externally visible header files in an include dir at the same level makes a lot of sense (I mostly don't need to do this). – Tim Bergel Feb 19 '14 at 13:09
  • possible duplicate of [Separate "include" and "src" folders for application-level code?](http://stackoverflow.com/questions/2924037/separate-include-and-src-folders-for-application-level-code) – mmmmmm Feb 19 '14 at 13:10
  • 1
    I do like include to be at the same level as src since it makes clear what is public and what is private to implementation. It is also easier to script install as it is a simple folder copy. – Eric Fortin Feb 19 '14 at 13:11
  • @Marc: I saw this question, but I didn't really learn something from the answers... May be my bad, but so far this new thread helped me more... I could put something like "see also" in the question – steffen Feb 19 '14 at 13:14

3 Answers3

3

If I were to create a library, I'd do the directory structure like so:

project/
       project_name/
       src/

Where project_name has the include files.
However for an application-level project, this would be my choice:

project/
    src/

src/ then would have all the files whether .h or .c.
In short, Do not use a folder for header files unless you're writing a library because a library needs to be more organized, also it gives ease of installation for the library.

2

I prefer to have the two folders on the same level. You have to choose your own way.

I prefer to separate the sources from the includes for the makefile for example and in order to gain more visibility on my project.

Project |--src/
        |--include/
        |--others/
        |--obj/
        |--Makefile
Zodoh
  • 100
  • 7
1

In my experience, having the include directory next to the src directory is more common in open-source libraries.

Note that some libraries even use another subdivision: They divide the library into modules (e.g. ModA, ModB etc), and then have an include and a src directory for each of the modules, i.e. ModA/include, ModA/src, ModB/include and ModB/src. See for example the PCL library.

anderas
  • 5,744
  • 30
  • 49