• ### Popular Now

• 13
• 15
• 27
• 9
• 9

This topic is 4930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How do you organize header files? If you have a complex file hierarchy like this:
/project
/graphics
/particlesystem
/terrain
/physics
/collision
/water
/ragdoll

managing paths in #includes can get quite annoying. I'd rather write
#include "terrain.h"

than
#include "graphics/terrain/terrain.h"

One obvious solution is to run a script at the beginning of every compilation that grabs all header files and puts it under /project/includes. The problem with this is that when there are errors in the header files, the IDEs bring up a file from /project/includes when you try to look at the error. You end up modifying a temporary file that gets overwritten the next time you compile which is obviously a large pain in the ass. How do you handle this situation?

##### Share on other sites
You can set additional include directories in your project so directory structure won't matter to the compiler.

##### Share on other sites
Quote:
 Original post by MaegaYou can set additional include directories in your project so directory structure won't matter to the compiler.

To make this easier to manage, it's also a good idea to put the most common headers in a single include directory or in a single static library called CoreLib or something like that.

##### Share on other sites
Well, adding many compiler directories also isn't a very good solution...

##### Share on other sites
Quote:
 Original post by CoffeeMugWell, adding many compiler directories also isn't a very good solution...Does GCC support precompiled headers?

And writing a batch file is? :/

##### Share on other sites
Quote:
 Original post by MaegaAnd writing a batch file is? :/

Took me 15 minutes after Olusei (damn, his name is hard to spell) recommended Python.

##### Share on other sites
Quote:
 Original post by CoffeeMugWell, adding many compiler directories also isn't a very good solution...

Some IDEs+compilers like CodeWarrior automatically do this. Which is inappropriate, IMO.

I ran into problems where I had files with the same name in different project subdirectories: 2 "common.h" files. CodeWarrior was always including the wrong one because it searches the project paths in a certain order, and includes the one that comes first.

So generally, I agree with this point

Quote:

As far as I know, yes. You'll definitely find more details on the gcc website.

Quote:
 How do you handle this situation?

I usually use relative pathing, e.g. "graphics/terrain/terrain.h"
It's not that bad - it forces you to think your directory structure before doing anything, which is good for things like CVS anyway.

##### Share on other sites
Quote:
 Original post by CoffeeMugTook me 15 minutes after Olusei (damn, his name is hard to spell) recommended Python.

Not really that hard. Just stop for a minute, learn the pronounciation of his name by heart, and then you'll be able to write it in a sec: Oluseyi.

I tried to learn the spelling first, but that led me to nowhere [smile]

##### Share on other sites
I don't see what is so annoying about putting the paths in the #include. What is there to manage?

It helps if the organization of folders in a project mirrors the organization of the software. The source file and its header file should be kept together. Splitting them into separate folders seems like a very bad idea.

Keep the number of folders in the include path to a minimum. On a large project, you easily have more than 100 folders. Putting all those folders into the include path is going to cause problems.