i have a main program with some include files, and i want to debug this files as well as the main program and use breakpoinds. Anyone knows how to do this??? Thanks
Javier, You need to DEFINE the variable in only ONE C file and DECLARE them as extern in the other files. For instance, if you define a global variable named "bar" in every C file you have and you want them all to refer to the same location in memory, then you'd put
unsigned char bar;
extern unsigned char bar;
I had already done exactly what you said, but the problem isn't with the compiler, but with the linker the full message is:
linking.. ***ERROR L104: MULTIPLE PUBLIC DEFINITIONS SYMBOL: variable MODULE: Timer.obj(Timer) (this is my c file)
Javier, You've missed something. The linker is complaining that there's more than one definition for "variable." This means that you have it in more than one C file without an extern tag in front of it. Another possibility is that there is a definition in one of the header files that you initially wanted to "debug." Either remove it from there, or put an extern tag in front of it if that's the case.
Jay, the exact definition is unsigned char tecla='N'; in the main C file an the declarations are extern unsigned char tecla='N'; in all other c files, and i still have the same problem. The "include" files that i initially wanted to debug are now saved as .c files and included in the sourcegroup. This files have pure C code. I don't know what else should i do. Thanks a lot
Javier, This problem is again, one that has only to do with basic C programming. Anything that allocates space is a DEFINITION. This means that any place you have an "=" after a variable to initialize it is a definition. So... you need to have the line
unsigned char tecla='N';
extern unsigned char tecla;
Thanks a lot jay and you all, finally i made it. As hans said i used a header for the extern an th e declarations in the main. I also worked without the "=", but i don't kwon why because i had already tested that
"the problem isn't with the compiler, but with the linker" NO. The problem is with neither the compiler nor the linker - it is with your code. The compiler only "sees" one 'C' source file at a time; each of your files is "correct" in itself, so you get no compiler errors. The problem comes when you try to link the two separate object files together; only then can it be seen that you have two files both defining variables with the same name! That's why the Linker tells you, "MULTIPLE PUBLIC DEFINITIONS" - because that's exactly what you've got! What you want is just a single definition, and to have all the rest of your code refer to that one "global" variable. If, on the other hand, you had wanted two distinct, independent global variables - then you would have had to rename at least one of them.