Public Group

# Compiling error " F1005 Include files nested too deep

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

## Recommended Posts

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.

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

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

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

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

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

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

##### Share on other sites
Quote:
 Original post by ernestovrI 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 youErnesto.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

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

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

• 40
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631371
• Total Posts
2999605
×

## Important Information

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

Sign me up!