• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# 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.

4 replies to this topic

### #1iwoplaza  Members

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 . Can you help?
P. S. I am using the compiler Dev C + +

### #2Laval B  Members

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
#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.

### #3iwoplaza  Members

Posted 29 May 2012 - 11:01 PM

Thanks, that worked ;).

### #4Miklas  Members

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 )

### #5Aardvajk  Members

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.