Jump to content

  • Log In with Google      Sign In   
  • Create Account


Multiple definition Error :(


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 iwoplaza   Members   -  Reputation: 156

Like
1Likes
Like

Posted 29 May 2012 - 12:38 PM

I'm in the process of creating a program to load and display the TGA files and I have these errors when compiling:
- Multiple definition of `tgaheader '
- First defined here
- Multiple definition of `tga '
- First defined here
- Multiple definition of `uTGAcompare '
- First defined here
- Multiple definition of `cTGAcompare '
- First defined here
- Multiple definition of `tgaheader '
- First defined here
- Multiple definition of `tga '
- First defined here
- Multiple definition of `uTGAcompare '
- First defined here
- Multiple definition of `cTGAcompare '
- First defined here
- D: \Ivo\Programming\C ++\Projects\3D Anim Test\Makefile.win [BuildError] ["3D] Error 1

It isn't written, where there is an error, but apparently something has been defined several times. But I checked many times and it turns out that these variables are defined only once Posted Image . Can you help?
P. S. I am using the compiler Dev C + +

Sponsor:

#2 Laval B   Crossbones+   -  Reputation: 4346

Like
2Likes
Like

Posted 29 May 2012 - 12:46 PM

Are you including the same header file in multiple files ?

You may need to enclose the definitions in the header by a set of directives like so

#if !defined(SOME_CONSTANTE_OF_YOUR_CHOICE)
#define		SOME_CONSTANTE_OF_YOUR_CHOICE
   //  Your definitions here ...
#endif

Event if those definitions are only found in one file, if the file is included in multiple other files (directly or indirectly), they will be difined multiple times.

I don't know Dev C++ nor the compiler you are using but #pragma once may also work.

I hope this helps.

Edited by Laval B, 29 May 2012 - 12:50 PM.

We think in generalities, but we live in details.
 
Alfred North Whitehead

#3 iwoplaza   Members   -  Reputation: 156

Like
0Likes
Like

Posted 29 May 2012 - 11:01 PM

Thanks, that worked ;).

#4 Miklas   Members   -  Reputation: 348

Like
0Likes
Like

Posted 30 May 2012 - 02:23 AM

*quick version*


If you want the 'long' version you can check out Wikipedia (#include guards).

This is a pretty 'beginners' error? Perhaps you should check out some more C++ books/tutorials to prevent you from making mistakes like this again. (The more you known from the language, the more optimized and clean your code will be. I speak out of experience Posted Image )

#5 Aardvajk   Crossbones+   -  Reputation: 5268

Like
0Likes
Like

Posted 31 May 2012 - 10:34 AM

We also need to be sure that these are multiple definition and not multiple declaration errors. All the header guards in the world won't prevent the linker crapping out if you declare a variable in a header that is included in more than one translation unit.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS