This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

#ifndef ignored

Other Parts Discussed in Thread: TMS320F28027

I am using CCS4 (Version: 4.0.2.01003) with the C2000 Compiler (Version 5.2.1) and working with a Piccolo TMS320F28027.

I have created a file called SRAM.h where I declare all my global variables. This file is included in several *.c-files. The SRAM.h file starts with

#ifndef _SRAM_H_

#define _SRAM_H_

and ends after declaring all variables with

#endif // end of _SRAM_H

 

 

The building of the project finishes with several error statements like "symbol "_sr_i_e1" redefined: first defined in "./Isr.obj"; redefined in "./control.obj""

In the console I can see the SRAM.h was build within 3 different *.obj files (Putting a small error in the SRAM.h file makes it possible because every time the file is used the error appears in log).

My question is now what I can to to prevent those errors? I thought with the #ifndef statement it would only be used once while compiling.

Greetings

  • This is the standard idiom for a header file re-inclusion guard, but it only works on a per-file basis.  If you define a variable in the header file and include it in more than one C source file, you'll get multiple definitions.  It is recommended that header files contain only declarations (prototypes and extern), not definitions (function bodies and non-extern variables).