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.


<code>
#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
</code>

Recommended Answers

All 4 Replies

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

[/code]
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.