Compiling error " F1005 Include files nested too deep

Started by
25 comments, last by ernestovr 19 years, 6 months ago
Hi guys I'm a newbie to this side of the bizz, I'm getting this error wile trying to compile my first GameEngine; here is the code that seem to be causing it. #pragma once //--------------------------------------------------------------------------- // Include Files //--------------------------------------------------------------------------- #include <windows.h> #include "Resource.h" #include "GameEngine.h" //--------------------------------------------------------------------------- // Global Variables //--------------------------------------------------------------------------- GameEngine* _pGame; Can someone give me a hint? Thank you very much ernesto.
Advertisement
The preprocessor can only follow a chain of includes to a certain depth. If one of your .h files in turn includes an .h file that itself includes an .h file, which also includes another .h file, etc., it will only go so deep until it backs out with an error. IIRC, this sort of behavior can also be triggered with an 'unguarded' .h file that includes itself. Without guards to force inclusion of the file only once (usually of the #ifndef/#define/#endif variet), you could conceivably get stuck in a chain whereby the file recursively includes itself until the threshold limit is reached.

So, make sure your Resource.h and GameEngine.h files do not include themselves, and check the chain of files they _do_ include to make sure you're not going over depth.
I think I understand I have 3 .h files, they are as follows GameEngine.h Resource.h and Skeleton.h. 2 of the file they have each other in there, I will play to find out how they should be.

Thank you very much.

Ernesto.

#pragma once

//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
GameEngine* _pGame;
=========================================================
//-----------------------------------------------------------------
// Icons Range : 1000 - 1999
//-----------------------------------------------------------------
#define IDI_SKELETON 1000
#define IDI_SKELETON_SM 1001
===========================================================
#pragma once
//---------------------------------------------------------------------------
// Include Files
//---------------------------------------------------------------------------
#include <windows.h>
#include "Resource.h"
#include "GameEngine.h"
//---------------------------------------------------------------------------
// Global Variables
//---------------------------------------------------------------------------
GameEngine* _pGame;
Which compiler are you using? It might not recognize #pragma once. Try putting every header file into #define guards like this:

#ifndef _FILENAMEGOESHERE_#define _FILENAMEGOESHERE_// header file goes here#endif
Don't rely solely on #pragma once. Always have #ifdef/#define/#endif inclusion guards. #pragma once is just an optimization (the compiler will not reopen the file), and is known to not work properly in some cases - even on compilers that do recognize it.

Why does GameEngine.h include itself?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thank you let me try that. I'm a total beginner and that is why the error was there. I'm using C++BuilderX.

Let me look at it for a sec.

Thank you.

ernesto.
I don't understand how to do this? I will need to read some more as it broke all the code. Does C++BuilderX support #pragma I understand that it's not the best to use but I'm realy lost if I try changing it to ifndef. Could I be a total bother and ask someone to explain how to use ifndef?

Sorry and thank you

Ernesto.

Which compiler are you using? It might not recognize #pragma once. Try putting every header file into #define guards like this:


#ifndef _FILENAMEGOESHERE_
#define _FILENAMEGOESHERE_

// header file goes here
#endif

Quote:Original post by ernestovr
I don't understand how to do this? I will need to read some more as it broke all the code. Does C++BuilderX support #pragma I understand that it's not the best to use but I'm realy lost if I try changing it to ifndef. Could I be a total bother and ask someone to explain how to use ifndef?

Sorry and thank you

Ernesto.

Which compiler are you using? It might not recognize #pragma once. Try putting every header file into #define guards like this:


#ifndef _FILENAMEGOESHERE_
#define _FILENAMEGOESHERE_

// header file goes here
#endif


Like so:

in resource.h:
#ifndef _RESOURCE_H_
#define _RESOURCE_H_

<insert code here>

#endif // _RESOURCE_H_

and similar code in GameEngine.h
Try changing your files to look more like this

// The first 2 lines of every .h file should look something // like this (you can change GAMEENGINE_H to a more suitable name tho)#ifndef GAMEENGINE_H#define GAMEENGINE_H//---------------------------------------------------------------------------// Include Files//---------------------------------------------------------------------------#include <windows.h>#include "Resource.h"#include "GameEngine.h"//---------------------------------------------------------------------------// Global Variables//---------------------------------------------------------------------------GameEngine* _pGame;// this is always the last line in your .h file#endif


#ifndef, #endif are called precomiler directives.

#ifndef checks of the name specified is not defined
if it is not, then it allows the compiler to include the whole file. If the name is defined, it jumps to #endif, without including your file.
Thank you very much I will tryied this right now. I have notice that everyone is talking about 2 of the 3 .h files I have but not about the 3rd is there a reason? This is my first time trying it so I created a GameEngine.cpp and .h a Skeleton.cpp and .h and a Resource.rc and .h should I had put the Skeleton and the Resource together? Sorry about the names but as I stated before I'm a total begginer.

Thank you everyone

Ernesto.

This topic is closed to new replies.

Advertisement