Jump to content
  • Advertisement
Sign in to follow this  
CoffeeMug

Organizing header files

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
Share on other sites
Quote:
Original post by Maega
You 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 this post


Link to post
Share on other sites
Quote:
Original post by CoffeeMug
Well, adding many compiler directories also isn't a very good solution...

Does GCC support precompiled headers?


And writing a batch file is? :/


GCC should support precompiled headers.

Share this post


Link to post
Share on other sites
Quote:
Original post by Maega
And writing a batch file is? :/

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

Share this post


Link to post
Share on other sites
Quote:
Original post by CoffeeMug
Well, 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:
Does GCC support precompiled headers?

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 this post


Link to post
Share on other sites
Quote:
Original post by CoffeeMug
Took 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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Coder
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 can't even begin to imagine how his name is pronounced [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!