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

## 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_

#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 on other sites
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.

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013763
×