Hello everyone,
I am having problem with a multiple public definition:

SYMBOL: currenpacketbeingsampled
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???


#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
#ifndef FALSE
#define FALSE 0
#ifndef NULL
#define NULL 0

#define AD0ECG 1
#define AD1PULSE 2
#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

1. Use code tags correctly:
[code=c] source

2. It's not a declaration only (with extern) for global variable: it's a very strange definition (with enormous macros currentpacketbeingsampled? or with macros xdata? ):

char xdata currentpacketbeingsampled;

Never add definitions (except classes and templates in C++) in header files.
Never use so strange syntax with macros.

Thanks for the reply ArkM, but im not sure what you are getting at.

I am writing my program in C, not C++. I wanted to place global variable declarations in the header file, that way it would be easier to keep track of the ones that are used in the associated C-file.
I require the variables to be declared in xdata, not data memory space, and currentpacketbeingsampled is a char variable.

What he's getting at is variables should be defined only in code files, the .C or .CPP files. NEVER put a definition in a header file. Only the extern goes in the .H file.

The guards are only useful when a header file is used twice during a single compilation. When you compile 2 separate sources individually, the headers files are processed as normal and each object file gets the definitions specified -- both sources will have currentpacketbeingsampled defined.

Thank you for the clarification. I'll just have to reorganize my declarations a little now, rather than keep fighting the compiler.

This question has already been answered. Start a new discussion instead.