views:

283

answers:

3

I'm currently working on a project that has scope to become quite large, however being relatively new to C++ and coming from a Java background I'm not sure about the best way to proceed.

I would like to have a directory structure similar to:

+ Root
- main.cpp
    + Engine
        + Core
        - foo.cpp
        - foo.h
        + Utilities
        - bar.cpp
        - bar.h
        + Sound
        + Input
        + Collision Detection
        + Particle System

At the moment I have a load of .ccp/.h files sitting in the Engine directory. When I move them to their appropriate folders and try to tie them together I just get pages of compile errors relating to classes being undefined. Can some kind soul help point a novice in the right direction?!

A: 

What do you mean by

things break horribly?

Your code doesn't compile? Strange bugs are introduced? Can you please be a bit more specific?

a_m0d
updated my post with further clarification, hope it's enough
Oli
yeah, that's more informative.
a_m0d
+2  A: 

You're almost certainly having trouble with include files being included. You need to add to the compile command -I flags for the directories from which you're bringing in your .h files.

Several of your directory names have spaces in them, so be careful that you're quoting the directory names correctly. Or, even better, since that's often a major pain, change, eg, "Collision Detection" to be "CollisionDetection" or "Collision_Detection"

Charlie Martin
Nail on the head, I had failed to tell the compiler which directories the .h files were in. Thanks a lot!
Oli
A: 

If you are using makefiles to compile your project, I would recommand you to switch to CMake, which would simplify the way you build the modular structure you are aiming at. The CMake keyword "include_directories" is the one you will need.

Bochon