tags:

views:

42

answers:

3

I'm trying to compile a code for bumper switches in my robot and i get this error:" Error - symbol 'tr' has multiple definitions." What does this mean? I'm painfully new to this...

+1  A: 

Hi there.

In your code, you might have more then one definition for the variable tr. e.g.

int tr = 0;

and in other part of the same code, or file

int tr = 0;

Do a search for tr in your code to see if it being defined multiple times.

Cheers. Jas.

Jason Evans
*"if it being declared multiple times"* - multiple declarations are fine, multiple definitions are (mostly) not.
Georg Fritzsche
@George - Point taken. Have updated post.
Jason Evans
+3  A: 

It depends whether you see the error at compile time or link time.

  • If you see it at link time (when building the program from object files), it means you have two or more object files, and the variable 'tr' (or function 'tr') is defined several times in different files.

  • If you see it at compile time (for a single file being converted to an object file), then you have defined the variable or function more than once in the given source file.

Jonathan Leffler
A: 

Maybe your header file (in which you might have declared tr) is being included in the same .c file multiple times.

One easy solution is to use Include Guards.

Lazer
For it to be a problem, the header must define the variable, not just declare it - and headers should 'never' (meaning 'very, very seldom') define variables.
Jonathan Leffler