Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

multiple definition of '_symbolname' first defined here

Status
Not open for further replies.

vijitron

Newbie level 6
Joined
Feb 22, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
i am using the structure and got this mulitlple definition issue,
Error: (Compiler: XC16 MPLAB X IDE)
build/default/production/drv/CC112X/Drv/Radio.o(.nbss+0x2): multiple definition of `_RadioChipType'
build/default/production/main.o(.nbss+0x0): first defined here

My structure in Radio_if.h file


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
typedef struct
{
 unsigned int deviceName;
 unsigned int id;
 unsigned int ver;
 unsigned int xoscFreq;
 
}radioChipType_t;
 
radioChipType_t RadioChipType;




i included this Radio_if.h file in Radio.c file and the Main.c file.
I added the Radio.c file in source folder of project in Mplab X.

i written the below as well to avoid multiple includes

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef RADIO_IF_H
#define    RADIO_IF_H
 
#ifdef    __cplusplus
extern "C" {
#endif
 
 
//codes here
 
 
#ifdef    __cplusplus
}
#endif
 
#endif




Can any help me why this error comes in
 

the statemen
Code:
t in Radio_if.h
Code:
radioChipType_t RadioChipType;
defines the variable RadioChipType, i.e. allocates memory for it

therefore if you include Radio_if.h in Radio.c and main.c you end up with two definitions and hence get the "multiple definition of `_RadioChipType'"

to overcome the problem declare RadioChipType as extern in the header file
Code:
typedef struct
{
 unsigned int deviceName;
 unsigned int id;
 unsigned int ver;
 unsigned int xoscFreq;
 
}radioChipType_t;
 
extern radioChipType_t RadioChipType;

and define it in Radio.c
Code:
radioChipType_t RadioChipType;

the program then only has one definition of RadioChipType in radio.C in all files it would be declared extern
 

Hi Horace

I understood this thank you, i had 2 more doubts in this same topic.
1. This same code is working in Hitech PICC8 without the 'extern' i don't know how?
2. I used the extern as below in radio_if.h

extern radioChipType_t RadioChipType;
but not defined in Radio.c file, but its compiling without error.

I am having another structure
Code:
typedef struct
{
  unsigned char data[PER_MAX_DATA];
   char  rssi;
  unsigned char lqi;
  unsigned char length;
  unsigned char addr;
}rxData_t;
/* Used to hold RX data accross different radios. No Mutex is implemented */
extern rxData_t *rxData;

i added extern both the structure variables after your reply. and compiled only this structure pointer throws error as

"undefined reference to `_rxData'

Can you explain how the non pointer structure is working without define, and this pointer structure says error.
 

Hi Horace

I understood this thank you, i had 2 more doubts in this same topic.
1. This same code is working in Hitech PICC8 without the 'extern' i don't know how?
2. I used the extern as below in radio_if.h

extern radioChipType_t RadioChipType;
but not defined in Radio.c file, but its compiling without error.

I am having another structure
Code:
typedef struct
{
  unsigned char data[PER_MAX_DATA];
   char  rssi;
  unsigned char lqi;
  unsigned char length;
  unsigned char addr;
}rxData_t;
/* Used to hold RX data accross different radios. No Mutex is implemented */
extern rxData_t *rxData;

i added extern both the structure variables after your reply. and compiled only this structure pointer throws error as

"undefined reference to `_rxData'

Can you explain how the non pointer structure is working without define, and this pointer structure says error.

do you actually reference (use) the variable RadioChipType anywhere in Radio.c or Main.c?

you can declare an exern
Code:
extern radioChipType_t RadioChipType;

and not define it with
Code:
radioChipType_t RadioChipType;

so long as it is not referenced - as soon as you rattempt to reference it you will get "undefined reference"
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top