locked
Fatal error, too many files included. What have I done wrong and how can I fix it?

    Question

  • So I went to follow and SDL tutorial (http://www.sdltutorials.com/sdl-tutorial-basics/), together with a tutorial on how to set it up on visual C++ (http://www.meandmark.com/sdlvisualc.pdf).

    Now it all compiles fine, except for these two errors:

     

     

    1>------ Build started: Project: SDL, Configuration: Debug Win32 ------

    1>  CApp_OnRender.cpp

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(1): fatal error C1014: too many include files : depth = 1024

    1>  CApp_OnLoop.cpp

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(1): fatal error C1014: too many include files : depth = 1024

    1>  CApp.cpp

    1>  Generating Code...

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

     

     

    Does anybody know what I have done wrong or how to fix this?


    NOOB DA WHOOP INCOMING
    Thursday, April 21, 2011 3:01 PM

Answers

  • You are going to have to show your code but the most likely cause is a recursive include with no guard.

    An example of this is

    //a.h
    #include "b.h"
    
    //b.h
    #include "a.h"
    
    //main.cpp
    #include "a.h"
    
    int main()
    {
      //do whatever
    }
    

    but the solution is simple, you use a guard. If you modify the headers just a little then it will fix it. You have two options though, you can use #pragma once, or #ifndef with #define. The #pragma option is ok if you only want to compile using VC, but it isn't really portable, so if you want other compilers to compile your code then use #ifdef. So you do it like this

    //a.h
    #pragma once
    #include "b.h"
    
    //b.h
    #pragma once
    #include "a.h"
    
    //main.cpp
    #include "a.h"
    
    int main()
    {
      //do whatever
    }
    

    or for the #ifndef

    //a.h
    #ifndef HEADERA
    #define HEADERA
    #include "b.h"
    
    //rest of the header must go in here
    
    #endif
    
    //b.h
    #ifndef HEADERB
    #define HEADERB
    #include "a.h"
    
    //rest of the header must go in here
    
    #endif
    
    //main.cpp
    #include "a.h"
    
    int main()
    {
      //do whatever
    }
    

    Done.


    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://ccprogramming.wordpress.com/
    • Marked as answer by xzbobzx Thursday, April 21, 2011 5:58 PM
    Thursday, April 21, 2011 4:17 PM

All replies

  • You are going to have to show your code but the most likely cause is a recursive include with no guard.

    An example of this is

    //a.h
    #include "b.h"
    
    //b.h
    #include "a.h"
    
    //main.cpp
    #include "a.h"
    
    int main()
    {
      //do whatever
    }
    

    but the solution is simple, you use a guard. If you modify the headers just a little then it will fix it. You have two options though, you can use #pragma once, or #ifndef with #define. The #pragma option is ok if you only want to compile using VC, but it isn't really portable, so if you want other compilers to compile your code then use #ifdef. So you do it like this

    //a.h
    #pragma once
    #include "b.h"
    
    //b.h
    #pragma once
    #include "a.h"
    
    //main.cpp
    #include "a.h"
    
    int main()
    {
      //do whatever
    }
    

    or for the #ifndef

    //a.h
    #ifndef HEADERA
    #define HEADERA
    #include "b.h"
    
    //rest of the header must go in here
    
    #endif
    
    //b.h
    #ifndef HEADERB
    #define HEADERB
    #include "a.h"
    
    //rest of the header must go in here
    
    #endif
    
    //main.cpp
    #include "a.h"
    
    int main()
    {
      //do whatever
    }
    

    Done.


    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://ccprogramming.wordpress.com/
    • Marked as answer by xzbobzx Thursday, April 21, 2011 5:58 PM
    Thursday, April 21, 2011 4:17 PM
  • Um, I used #pragma once, which gave me a whole bunch more errors... :|

    Errors:

     

     

     

    1>------ Build started: Project: SDL, Configuration: Debug Win32 ------

    1>  CApp_OnRender.cpp

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(3): error C2653: 'CApp' : is not a class or namespace name

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(4): error C2065: 'Running' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(5): warning C4508: 'CApp' : function should return a value; 'void' return type assumed

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(7): error C2653: 'CApp' : is not a class or namespace name

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(8): error C3861: 'OnInit': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(12): error C2065: 'SDL_Event' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(12): error C2146: syntax error : missing ';' before identifier 'Event'

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(12): error C2065: 'Event' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(14): error C2065: 'Running' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(15): error C2065: 'Event' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(15): error C3861: 'SDL_PollEvent': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(16): error C2065: 'Event' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(16): error C3861: 'OnEvent': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(19): error C3861: 'OnLoop': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(20): error C3861: 'OnRender': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(23): error C3861: 'OnCleanup': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(29): error C2146: syntax error : missing ';' before identifier 'theApp'

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(29): warning C4551: function call missing argument list

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(29): error C2065: 'theApp' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(31): error C2065: 'theApp' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(31): error C2228: left of '.OnExecute' must have class/struct/union

    1>          type is ''unknown-type''

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp_onrender.cpp(3): error C2653: 'CApp' : is not a class or namespace name

    1>  CApp_OnLoop.cpp

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(3): error C2653: 'CApp' : is not a class or namespace name

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(4): error C2065: 'Running' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(5): warning C4508: 'CApp' : function should return a value; 'void' return type assumed

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(7): error C2653: 'CApp' : is not a class or namespace name

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(8): error C3861: 'OnInit': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(12): error C2065: 'SDL_Event' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(12): error C2146: syntax error : missing ';' before identifier 'Event'

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(12): error C2065: 'Event' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(14): error C2065: 'Running' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(15): error C2065: 'Event' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(15): error C3861: 'SDL_PollEvent': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(16): error C2065: 'Event' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(16): error C3861: 'OnEvent': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(19): error C3861: 'OnLoop': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(20): error C3861: 'OnRender': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(23): error C3861: 'OnCleanup': identifier not found

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(29): error C2146: syntax error : missing ';' before identifier 'theApp'

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(29): warning C4551: function call missing argument list

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(29): error C2065: 'theApp' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(31): error C2065: 'theApp' : undeclared identifier

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp.h(31): error C2228: left of '.OnExecute' must have class/struct/union

    1>          type is ''unknown-type''

    1>l:\yannic\bobstudios\codes\sdl\sdl\capp_onloop.cpp(3): error C2653: 'CApp' : is not a class or namespace name

    1>  CApp_OnInit.cpp

    1>  CApp_OnEvent.cpp

    1>  CApp_OnCleanup.cpp

    1>  CApp.cpp

    1>  Generating Code...

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Codes:
    CApp.h
    #pragma once
    #include "CApp.h"
    CApp::CApp() {
     Running = true;
    }
    
    int CApp::OnExecute() {
     if(OnInit() == false) {
      return -1;
     }
    
     SDL_Event Event;
    
     while(Running) {
      while(SDL_PollEvent(&Event)) {
       OnEvent(&Event);
      }
    
      OnLoop();
      OnRender();
     }
    
     OnCleanup();
    
     return 0;
    }
    
    int main(int argc, char* argv[]) {
     CApp theApp;
    
     return theApp.OnExecute();
    }
    
    CApp.cpp
    #pragma once
    #include "CApp.h"
    CApp::CApp() {
    	Surf_Display = NULL;
     Running = true;
    }
    
    int CApp::OnExecute() {
     if(OnInit() == false) {
      return -1;
     }
    
     SDL_Event Event;
    
     while(Running) {
      while(SDL_PollEvent(&Event)) {
       OnEvent(&Event);
      }
    
      OnLoop();
      OnRender();
     }
    
     OnCleanup();
    
     return 0;
    }
    
    int main(int argc, char* argv[]) {
     CApp theApp;
    
     return theApp.OnExecute();
    }
    
    Other tiny codes:
    //CApp_OnCleanup.cpp
    
    #pragma once
    #include "CApp.h"
    void CApp::OnCleanup() {
     SDL_Quit();
    }
    
    
    //CApp_OnEvent.cpp
    
    #pragma once
    #include "CApp.h"
    void CApp::OnEvent(SDL_Event* Event) {
     if(Event->type == SDL_QUIT) {
      Running = false;
     }
    }
    
    
    //CApp_OnInit
    
    #pragma once
    #include "CApp.h"
    bool CApp::OnInit() {
     if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
      return false;
     }
    
     if((Surf_Display = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) {
      return false;
     }
    
     return true;
    }
    
    
    //CApp_OnLoop.cpp
    
    #pragma once
    #include "CApp.h"
    void CApp::OnLoop() {
    }
    
    
    //CApp_OnRender.cpp
    
    #pragma once
    #include "CApp.h"
    void CApp::OnRender() {
    }
    
    I hope you can help me.

     


    NOOB DA WHOOP INCOMING
    • Edited by xzbobzx Thursday, April 21, 2011 5:03 PM
    Thursday, April 21, 2011 4:42 PM
  • Well, all of these errors have nothing to do with the original problem, so it is fixed now.

    Also, the code you posted are you sure it is accurate? It seems like the code in capp.h is the same as in capp.cpp so you should check that.


    Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
    Visit my (not very good) blog at
    http://ccprogramming.wordpress.com/
    Thursday, April 21, 2011 4:53 PM
  • Well thanks for your fix.

    And yea, the code is accurate, at least I think it is.

    I might have to go through the entire tutorial again though... :P


    NOOB DA WHOOP INCOMING
    Thursday, April 21, 2011 5:30 PM