Help: 'error: redefinition'

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Help: 'error: redefinition'

 
0
  #1
Sep 12th, 2007
Hello there, I have here a problem with the compilation of my program. The compiler tells me that my typedefs are redefined, but I defined it only once. Ok, heres the score, I have here a header file (let's name this as file X) that contains all the typedefs that I need (so that I will be able to reuse it to other files). I have included it to the two files (let's say, file A and file B) that really needs it badly and these two files (file A and B) are included to a file that needs them too (let's call this one as file C). Whenever I compile file C, I get the error of redefinition. Is there something wrong with the way I mess with the files? I'm using gcc thus involving Makefile.

Thanks!
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,484
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: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help: 'error: redefinition'

 
0
  #2
Sep 12th, 2007
you header file need code gards to prevent that, like this
  1. #ifndef MYHEADER
  2. #define MYHEADER
  3. // code goes here
  4.  
  5. #endif
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,311
Reputation: vishesh is on a distinguished road 
Solved Threads: 36
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: Help: 'error: redefinition'

 
1
  #3
Sep 12th, 2007
You could also use #pragma once but it is compiler dependent and deprecated. Its generally used with MSVC++.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,771
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 743
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Help: 'error: redefinition'

 
1
  #4
Sep 12th, 2007
>You could also use #pragma once but it is compiler dependent and deprecated.
All pragmas (well, most with the coming of C99) are compiler dependent. You should avoid them whenever possible. And if #pragma once is compiler dependent, how can you say that it's deprecated? Have all compilers documented it as deprecated? Anyway, the only real advantage of #pragma once is that you don't have to worry about naming collisions in your inclusion guards, and that's not worth the loss of portability.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,311
Reputation: vishesh is on a distinguished road 
Solved Threads: 36
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: Help: 'error: redefinition'

 
0
  #5
Sep 12th, 2007
Originally Posted by Narue View Post
>You could also use #pragma once but it is compiler dependent and deprecated.
All pragmas (well, most with the coming of C99) are compiler dependent. You should avoid them whenever possible. And if #pragma once is compiler dependent, how can you say that it's deprecated? Have all compilers documented it as deprecated? Anyway, the only real advantage of #pragma once is that you don't have to worry about naming collisions in your inclusion guards, and that's not worth the loss of portability.
Of course all pragmas are compiler dependent and different compilers could have different pragmas. I didn't mentioned it all but I think its pretty clear. By deprecated I meant its somewhat strongly not advised. I have written what I have read and inferred from it sometime. somewhere.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Re: Help: 'error: redefinition'

 
0
  #6
Sep 12th, 2007
I placed #pragma once in file X and it worked. Thanks guys.
Retreat!!!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,311
Reputation: vishesh is on a distinguished road 
Solved Threads: 36
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: Help: 'error: redefinition'

 
0
  #7
Sep 13th, 2007
Didn't this worked as suggested by Ancient Dragon . Its better to use that and you must know how to use it
  1. #ifndef MYHEADER
  2. #define MYHEADER
  3. // code goes here
  4.  
  5. #endif
Last edited by vishesh; Sep 13th, 2007 at 6:17 am.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC