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.

MSP430FR6820: multiple declarations of global variables

Expert 6230 points
Part Number: MSP430FR6820


We use MSP430FR6820 and need to create global variables on certain memory locations in RAM to be in a row without gaps.

There is definition of globalvar.h

#ifndef GLOBALVAR_H_
#define GLOBALVAR_H_

#pragma LOCATION(Var1ToSafe,0x1c51)
char Var1ToSafe;
#pragma LOCATION(Var2ToSafe,0x1c52)
int Var2ToSafe;
#pragma LOCATION(Var3ToSafe,0x1c54)
int Var3ToSafe[4];
#pragma LOCATION(Var4ToSafe,0x1c5C)
long Var4ToSafe;


If I include this globalvar.h once, everything is O, but if I include this globalvar.h twice, I have errors:

Description Resource Path Location Type symbol "Var1ToSafe" redefined: first defined in "./adc2temp.obj"; redefined in "./main.obj" symbol "Var1ToSafe" redefined: first defined in "./adc2temp.obj"; redefined in "./main.obj" main.c /TestLinkovani C/C++ Problem

Please, can you give advice how to solve this problem?

(This globalvar.h is only example, I need declare 100 variables with diferent types and I can´t use structure or another solution of datatyping, I need variables in a row on the certain address in RAM).

Thanks for your feedback and help.
TI Customer

  • Your .h file contains variable definitions. There should only be one definition of any (global) variable in the program, typically in a .c file.

    The corresponding .h file should contain only declarations, something like "extern char Var1ToSafe;".

    Though CCS "cc" User Guide (SLAU132S) Sec. 5.12.21 doesn't say it explicitly, its examples only apply #pragma LOCATION to definitions, so they would only appear in the .c file. I expect the linker figures it out.

    [Edit: Have you considered bracketing your variable group with #pragma SET_DATA_SECTION(), and then modifying your linker file to place that section where you want it? That won't set the precise location for each variable, but it will put them in the area of memory you want. And it will save some typing.]

  • Hi Bruce,

    your idea with bracketing variable group should solve our problem.

    Thanks a lot!

**Attention** This is a public forum