Jump to content
  • Advertisement
Sign in to follow this  
Billr17

Organizing Source Code Files.

This topic is 4719 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

I've seen this done before, but I'm unsure how to accomplish this. I've looked around, and theres not many articles on this subject. I would like to have a source code folder that branches into a header and source sub folders. From there they are broken down into engine, gui, utilities, etc. How would I go about setting up VS Studio 6.0 to handle a project like this. As it stands right now; the only way the .cpp files can see the headers is if I mnaually go into options and set the directories. I would rather not do this since I am working on other projects that I don't want to have access to this code. My guess is that I would need to make a Makefile to build all of the .cpp files code and dump it into the release folder. Then all my project would have to do is link it. Any suggestions or ideas would be appreciated. Bill

Share this post


Link to post
Share on other sites
Advertisement
There are a couple of options to accomplish what you are looking for.

(1) First one involves setting up an include directory for the project. Note that this does not affect all projects, only the current one. Here's how you do it:

Project->Settings->C/C++->Preprocessor[Category]

In the third text box down, it'll say, "Additional include directories". Put your directory that contains your header files there.

(2) Another option is to use path relative #include directives:

For example, if you have

/base
-> /src
-> /include

All files under your source directory could include files from 'include' like so:

// --------- .cpp file -------
#include "../include/myHeader.h"

Just remember the simple rule that '..' backs up a folder. However, the drawback to this approach is that it requires anybody else who compiles your code to have a similar directory structure (which isn't usually a problem anyway).

Hope this helps.

- Greg

Share this post


Link to post
Share on other sites
Well, I've had trouble getting extra include directories in the project to work before (VC++ 6). I was trying to use relative directories in the project settings to let files from one directory include those from the other, but for some reason I couldn't get it to work.

Anyway the way I usually do this is to have multiple projects (one for each directory) each one of which compiles to a static .lib file, and then link these. It's also worth noting that if you ever wanted to have a source tree which works on Linux you may have to do this since automake doesn't allow source files in different directories.

Share this post


Link to post
Share on other sites
Thank you for the suggestions. I used morx's suggestion for this project and will keep ZQJ's suggestion in mind for a possible cross platform adventure in the near future. I've been looking for information on this topic for some time now. Its been a hard topic to find anything about. Someone should write an article on different methods of arranging source code and the benefits and disadvantages of each way. I think it would be helpful to a lot of people.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!