Jump to content
  • Advertisement
Sign in to follow this  
sspeedy

organizing multiple source/header files

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

Ok, hi, I might look retarded but it's been a LONG time since I've had to break up the main.c file in to several .c files for organization... plus, it'll look a lot cleaner ;) Welp, I'm using allegro for game programming and dev-c++. I originally had one main.c file, which compiled fine. Then, I moved variables (initializations/declarations) and put them into a main.h file. Now, to start organizing, I only took one function, the intialization function from main.c, and put it into a new file initilization.c. Here's what's in each file for #includes: main.h:
#ifndef _link_h_
#define _link_h_

#include <allegro.h> 
#include "initialize.c"
....
..
.
#endif
main.c:
#include "main.h"
initialize.c:
#include "main.h"
I'd appreciate any help in the matter. THe compiler errors I'm getting are:
initialize.c: In function `initialize_gameengine':
initialize.c:13: error: `MODE' undeclared (first use in this function)
initialize.c:13: error: (Each undeclared identifier is reported only once
initialize.c:13: error: for each function it appears in.)
initialize.c:13: error: `WIDTH' undeclared (first use in this function)
initialize.c:13: error: `HEIGHT' undeclared (first use in this function)

In file included from main2a.c:11:
main.h: At top level:
main.h:121: error: conflicting types for 'grabframe'
initialize.c:38: error: previous implicit declaration of 'grabframe' was here
MODE/WIDTH/HEIGHT are defined in main.h. TIA.

Share this post


Link to post
Share on other sites
Advertisement
I'm assuming you didn't try to put executable code into a .h file at the moment.

The problem with your code is that initialize.c is being compiled before the rest of the code in main.h after the #include "initialize.c" is being accessed. The line containing #include "initialize.c" is where you are getting mixed up. Please remove this line completely and never write an include to a C file again.

Instead put in a bunch of extern directives that will declare the function prototypes and variables from intitialize.c in main.h . Then make a separate initialize.h file with externs to all of the variables in main.c that are accessed by initialize.c .

Then you can access them in the program by manipulating the project file so that it doesn't have to compile the entire program at once. For DevC++ you add the initialize.c to the project file and its object file should automatically be compiled separately and linked to the main executable when you build the project.

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!