943,875 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1093
  • C++ RSS
Mar 18th, 2009
0

Too many includes

Expand Post »
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:

C++ Syntax (Toggle Plain Text)
  1. #ifdef WIN32
  2. #define WIN32_LEAN_AND_MEAN
  3. #include <windows.h>
  4. #endif
  5.  
  6. // System Includes //
  7. #include <iostream>
  8. #include <cstdio>
  9. #include <fstream>
  10. #include <string>
  11.  
  12. // Imported Libraries //
  13. #include "xmlParser.h"
  14.  
  15. // Our Includes //
  16. #include "image.h"
  17. #include "enum.cpp"
  18.  
  19. // OpenGL Includes //
  20. #include <GL/gl.h>
  21. #include <GL/glut.h>
  22.  
  23. using namespace std;

Each file has
C++ Syntax (Toggle Plain Text)
  1. #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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
toadzky is offline Offline
96 posts
since Mar 2007
Mar 18th, 2009
0

Re: Too many includes

Is this really what you want?
#include "enum.cpp"
Reputation Points: 163
Solved Threads: 91
Posting Pro in Training
nucleon is offline Offline
476 posts
since Oct 2008
Mar 18th, 2009
0

Re: Too many includes

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

Re: Too many includes

Click to Expand / Collapse  Quote originally posted by toadzky ...
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]
Last edited by mitrmkar; Mar 18th, 2009 at 1:47 pm.
Reputation Points: 1105
Solved Threads: 389
Posting Virtuoso
mitrmkar is offline Offline
1,714 posts
since Nov 2007
Mar 18th, 2009
0

Re: Too many includes

Yes, it should definitely be .h if it has no actual code.
Do you have include guards in your header files?
Reputation Points: 163
Solved Threads: 91
Posting Pro in Training
nucleon is offline Offline
476 posts
since Oct 2008
Mar 18th, 2009
0

Re: Too many includes

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
toadzky is offline Offline
96 posts
since Mar 2007
Mar 18th, 2009
0

Re: Too many includes

You must use include guards. Do this:
C++ Syntax (Toggle Plain Text)
  1. #ifndef FILENAME_H_
  2. #define FILENAME_H_
  3. // header code here
  4. #endif
Reputation Points: 163
Solved Threads: 91
Posting Pro in Training
nucleon is offline Offline
476 posts
since Oct 2008
Mar 18th, 2009
0

Re: Too many includes

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
toadzky is offline Offline
96 posts
since Mar 2007
Mar 18th, 2009
0

Re: Too many includes

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.
C++ Syntax (Toggle Plain Text)
  1. //"xmlParser.h"
  2. #ifndef XMLPARSER_H
  3. #define XMLPARSER_H
  4. // stuff goes here
  5.  
  6. #endif
Last edited by Ancient Dragon; Mar 18th, 2009 at 4:07 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,952 posts
since Aug 2005
Mar 18th, 2009
0

Re: Too many includes

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
toadzky is offline Offline
96 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problem with functions
Next Thread in C++ Forum Timeline: static_cast vs (type)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC