i have a configuration file to define some of the functions and macros .
my_config.cfg
#define index_zero 0
#define index_one 1
#define index_two 2
#define index_three 3
unit8 index;
typedef struct
{
const UINT16 first_value;
const UINT16 second_value;
UINT16 updated_value;
}test;
test my_array[3];
test my_array[3] =
{
{0, 22, 0},
{0, 44, 0},
{0, 33, 0}
};
static void set_zero_value (void)
{
for(i=0;i<3;i++)
{
my_array[i].updated_value = first_value;
}
}
static void set_temp_value (void)
{
for(i=0;i<3;i++)
{
my_array[i].updated_value = second_value;
}
}
static UINT16 update_value (uint8 index)
{
return (my_array[index].updated_value);
}
i am including this .cfg file in another file for updating the values and also i am defining another function to check the running status .
sample1.c
#include "my_config.cfg"
#include "sample1.h"
boolean isrunning(void)
{
if(condition1)
return true ;
else
return false ;
}
set_zero_value();
set_temp_value();
and also in another file , i am checking whether it is running or not , if running , i am updating some of the values from my config file .
sample2.c
#include "my_config.cfg"
#include "sample1.h"
#include "sample2.h"
if(isrunning())
{
UINT16 first = update_value(index_zero);
UINT16 second = update_value(index_one);
UINT16 third = update_value(index_two);
}
After compiling the code , I am getting the error at linkage time
multiple definition of `my_array` in object file in sample2.o and sample1.o
and
multiple definition of `index` in object file in sample2.o and sample1.o
i don't know why i am getting this error at the time of linkage , i have to include both header files to access those functions . Any help ?
wrap your cfg file file a conditional preprocessor directive like #ifndef, #define #endif https://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_4.html