This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Trying to debug include files

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

Parents Reply Children
  • I did what you said, but i have a new problem
    Several of my C files uses the same global variables declared on main, but the compiler tells me:

     Error 202: "var_name" undefined identifier 

    It happens in all of the files that uses this variable.
    Any way to solve it????
    Thanks again

  • Javier,

    At the top of all the files OTHER than main that use these variables, you must put an "extern" declaration to let the linker know where to find these variables. For instance, if you had an integer variable named "var1" in main.c that you wanted to use in foo.c, then somewhere at the top of foo.c you would put:

    extern int var1

    That being said, it's becoming quite clear that you've never done any C programming before. Let me be the first to suggest that a microcontroller platform is NOT the place you should learn how to do so.

  • whoops... throw a ";" after the var1 in my last message.

  • Thanks a lot. I have done some C programming, but it's the first time i try to debug the include files....

  • Know i get an error
    ERROR L104 : MULTIPLE PUBLIC DEFINITIONS

    HOw do i solve this. I use the global variables in several c files besides main

  • 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;

    in any ONE of the C files (usually there's one that makes the most sense). Then you'd add

    extern unsigned char bar;

    to all the other files that use it. How can you have written C programs before and not come across this? With this little familiarity with the language, I doubt you're going to meet with any success.

  • At the top of all the files OTHER than main that use these variables, you must put an "extern" declaration

    No. As I keep pointing out, pretty much every occurence of the word 'extern' in a .c file is a design error.

    You should have this 'extern' in a header file instead, and #include that in exactly those source files that refer to it, including the one that holds the definition of the variable in question.

  • At the top of all the files OTHER than main that use these variables, you must put an "extern" declaration

    No. As I keep pointing out, pretty much every occurence of the word 'extern' in a .c file is a design error.

    You should have this 'extern' in a header file instead, and #include that in exactly those source files that refer to it, including the one that holds the definition of the variable in question.

  • Hans,

    While I understand your philosophy, keep in mind that Javier started off this thread by asking how he could STEP THROUGH CODE included in a header file. I'm just going for simplicity here at the moment. He'll learn the theology of things the hard way at some later date, no doubt.

  • first time i try to debug the include files....

    Just to make this extra clear: the problem is this that there's not supposed to be anything in an include file that would need to be debugged (in the sense that you need to search for errors in there although the compiler and linker already accepted the program).

    You really need to brush up your basic knowledge of C. I suggest the comp.lang.c FAQ for starters, or possibly one of the textbooks recommended by that FAQ.

  • 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)
    
    
    thanks

  • 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';

    in only ONE file and then

    extern unsigned char tecla;

    in all the other files that use this variable. If the "=" are in all the files, then the linker will rightfully continue to complain about multiple definitions.