Hello everyone, I am having problem with a multiple public definition:
ERROR L104: MULTIPLE PUBLIC DEFINITIONS SYMBOL: currenpacketbeingsampled MODULE: DataSampling.obj (DATASAMPLING) DEFINED: Main.obj (MAIN)
The variable in question is defined only once in the header file, and only used in the associated C file. From my understanding a macro guard should prevent the error that i am getting. The header file code is shown below, can anyone see a reason why i would be getting the error???
Thanks.
#ifndef DS_H #define DS_H #include <stdio.h> #include <stdlib.h> #include "hal.h" #include "cc1010eb.h" #include "Reg1010.h" #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #ifndef NULL #define NULL 0 #endif #define AD0ECG 1 #define AD1PULSE 2 #define AD2TEMPSENSOR 3 #define AD2RSSI 4 void InitialiseDataSampling(byte xdata DataTypes); void SampleData(bool xdata condition); void SetupADC(char SetupType); extern byte xdata ECGcount; //The destination element of the next ECG data in ECGsamples[] extern byte xdata TEMPcount; //The destination element of the next temperature data in TempData[] char xdata currentpacketbeingsampled; extern char xdata nextpackettosend; extern byte xdata DataSampled; extern short int ECGsamples[50]; extern int maximumvalue; #endif //DS_H
DS_H prevents the contents of the header from being included more than once in a single C file. But what prevents currentpacketbeingsampled from being declared in each C file where this header is included?
Jon
"The variable in question is defined only once in the header file" (my emphasis)
That's your problem!
You should not define variables in the header file - otherwise, as Jon says, every file which includes that header will have a definition of the variable!
Your header should contain only declarations - see: c-faq.com/.../decldef.html
Note that this is bog standard 'C' - nothing specifially to do with Keil or C51...
In short, you forgot the extern keyword on this specific line:
char xdata currentpacketbeingsampled;
Compare with the other lines.
Thank you for your help.