multiple definition error in MCC/Linker (possible bug?)

Hey,
I have just been working on my code, when all of a sudden I started getting multiple definition errors from the linker on a variable named drive_mode.
I searched through all the files involved (grep drive_mode {.c,.h}), and found only one definition.
I have also deleted all the object files, then re-compiled from scratch and changed the variables name.
I think this is a bug with MCC or the linker because it started out being one variable, and now it is this one.
Sorry I cant give any compiler output, but I am at a regional, and can not move the computer with the code on it.
If anyone really wants, I could get it tonight (when I go home thou).
I have asked a couple of the programmers here, and they cant figure out what the problem is either.
Thanks a lot!

That symptom points to one of two things. Either you have more than one #include for the same .h file (and you’re not “protecting” it with #ifdef), or you have added the same .c file to the project twice. The first problem would show up in the code. The second problem would not. Try looking at the project window and make sure you only have each file in there once. If something is duplicated, remove the extra one.

I havent added any #include statements, so I dont think it would be that

I am not using the MLAB IDE (vim + make), so I do not think that would be an issue. I get the same problem when I do load it in to the IDE thou.

I have also tryed to build it on 4 different macines, so it is not my computer that is the problem either.
Thanks for the quick reply thou.

I dont know if this helps, but I searched the default code and drive_mode is not in the map file - so if its in your code you must have added it

the obvious thing to do is comment it out where you know it is (where you want it to be) and see if it compiles

if it does then search the .lst file and see where the other one is or check the map file and see if its in there - if its in the map file then its getting declared somewhere

could it be in the file with all the constants? did you declare it as a constant once and foget?

Where did the grep find it? Was it in a .h file? What does the definition look like?

What you should have is something like

int drive_mode;

in ONE .c file. And (assuming you really need to reference the variable in another program) in your .h file, put

extern int drive_mode;

If you have the

int drive_mode;

(without the extern keyword) in a .h file, and #include it in multiple files, you will get a multiple definition error.

Hey,
Thanks for all the help.
I finally figured out what it was.
When I defined variables in the .h file, it tryed to use them in all the .c files. This, of corse, lead to conflicts.
This could have been fixed by using the extern statement (#extern int drive_mode), or by doing what I did - just putting them in the .c files where they are needed.
I finaly figured this out after and hour or so of looking over/commenting stuff in and out with one of our mentors who works with C.