Too many includes

Thread Solved

Join Date: Mar 2007
Posts: 68
Reputation: toadzky is an unknown quantity at this point 
Solved Threads: 0
toadzky toadzky is offline Offline
Junior Poster in Training

Too many includes

 
0
  #1
Mar 18th, 2009
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:

  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
  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Too many includes

 
0
  #2
Mar 18th, 2009
Is this really what you want?
#include "enum.cpp"
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 68
Reputation: toadzky is an unknown quantity at this point 
Solved Threads: 0
toadzky toadzky is offline Offline
Junior Poster in Training

Re: Too many includes

 
0
  #3
Mar 18th, 2009
yes. it's just a cpp file (probably could be .h) that holds some enums. no actual code in it or includes
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 1,274
Reputation: mitrmkar is a name known to all mitrmkar is a name known to all mitrmkar is a name known to all mitrmkar is a name known to all mitrmkar is a name known to all mitrmkar is a name known to all 
Solved Threads: 264
mitrmkar mitrmkar is offline Offline
Nearly a Posting Virtuoso

Re: Too many includes

 
0
  #4
Mar 18th, 2009
Originally Posted by toadzky View Post
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 12:47 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Too many includes

 
0
  #5
Mar 18th, 2009
Yes, it should definitely be .h if it has no actual code.
Do you have include guards in your header files?
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 68
Reputation: toadzky is an unknown quantity at this point 
Solved Threads: 0
toadzky toadzky is offline Offline
Junior Poster in Training

Re: Too many includes

 
0
  #6
Mar 18th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Too many includes

 
0
  #7
Mar 18th, 2009
You must use include guards. Do this:
  1. #ifndef FILENAME_H_
  2. #define FILENAME_H_
  3. // header code here
  4. #endif
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 68
Reputation: toadzky is an unknown quantity at this point 
Solved Threads: 0
toadzky toadzky is offline Offline
Junior Poster in Training

Re: Too many includes

 
0
  #8
Mar 18th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 16,480
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1601
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Too many includes

 
0
  #9
Mar 18th, 2009
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.
  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 3:07 pm.
The most important thing in the Olympic Games is not to win but to take part, just as the most important thing in life is not the triumph but the struggle. The essential thing is not to have conquered but to have fought well.
-Pierre de Coubertin, The Olympic Creed Inspired by Bishop Ethelbert
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 68
Reputation: toadzky is an unknown quantity at this point 
Solved Threads: 0
toadzky toadzky is offline Offline
Junior Poster in Training

Re: Too many includes

 
0
  #10
Mar 18th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 702 | Replies: 9
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC