954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Too many includes

I like really clean code so I want to pull all of the common includes into a separate file and then include that single file in all my other files. Also makes it easier if I start using a new or different library cuz I only have to change it in one place.

here is what i have in my include.h file:

#ifdef WIN32
   #define WIN32_LEAN_AND_MEAN
   #include <windows.h>
#endif

//    System Includes   //
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>

//    Imported Libraries   //
#include "xmlParser.h"

//    Our Includes   //
#include "image.h"
#include "enum.cpp"

//    OpenGL Includes   //
#include <GL/gl.h>
#include <GL/glut.h>

using namespace std;


Each file has

#include "include.h"

Simple enough.

VS2008 gives me error C1014: Too many includes. I'm pretty sure from browsing other posts that this means I'm doing recursive including. But if I do it any other way it says it can't find any of the data types that are defined in the includes.

Thanks for any help.

toadzky
Junior Poster in Training
96 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Is this really what you want?
#include "enum.cpp"

nucleon
Posting Pro in Training
478 posts since Oct 2008
Reputation Points: 163
Solved Threads: 91
 

yes. it's just a cpp file (probably could be .h) that holds some enums. no actual code in it or includes

toadzky
Junior Poster in Training
96 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 
yes. it's just a cpp file (probably could be .h) that holds some enums. no actual code in it or includes

There is a contradiction, in your first post you say that "Each file has: #include "include.h"". If enum.cpp actually includes include.h, that results in the error you described.

[EDIT]
Assuming "Each file" refers to source files ...
[/EDIT]

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

Yes, it should definitely be .h if it has no actual code.
Do you have include guards in your header files?

nucleon
Posting Pro in Training
478 posts since Oct 2008
Reputation Points: 163
Solved Threads: 91
 

the enum file doesn't include anything.

as for guards, i tried using them but it says that it cant find any of the types from the includes.

toadzky
Junior Poster in Training
96 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

You must use include guards. Do this:

#ifndef FILENAME_H_
#define FILENAME_H_
// header code here
#endif
nucleon
Posting Pro in Training
478 posts since Oct 2008
Reputation Points: 163
Solved Threads: 91
 

I know I should have guards. However, if I include the guards, NONE of the includes happen. It says it can't find ANY of the data types included in the guard.

toadzky
Junior Poster in Training
96 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

You put the guards in the *.h files that you wrote, not the STL or other system files. If you are getting errors, then you didn't do it correctly, and you should post the header file w/guards so we can see what you did.

//"xmlParser.h"
#ifndef XMLPARSER_H
#define XMLPARSER_H
// stuff goes here

#endif
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Can't tell you why it wasn't working the first time, because definitely tried guards before I even posted this. I gave up for a while and just focused on getting my code working. Now it's working.

Thanks for your patience and your help.

toadzky
Junior Poster in Training
96 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You