Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Declared all my declaration in one file called ADeclaration.h and included this file in all my module C files.

i.e.

I have
VB
MAIN.c (MAIN)
 Port_IO.c (PORT_IO)
 STORAGE.c (STORAGE)
 TEMPERATURE.c (TEMPERATURE)
 CONVERT.c (CONVERT)
 UART.c (UART)
 RTC.c (RTC)
 I2C.c (I2C)
 ISR.c(ISR)
 FLASH.c (FLASH)


All the declaration of this files are in Adeclaration.h

Now I am getting my project.M51 with
Program Size: data=157.5 xdata=5988 code=11148
LINK/LOCATE RUN COMPLETE. 29 WARNING(S), 294 ERROR(S)

and the target is not created

most of the error are like
VB
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS
    SYMBOL:  LOCAL
    MODULE:  STORAGE.obj
Posted
Updated 12-Oct-10 22:46pm
Comments
Dalek Dave 13-Oct-10 4:46am    
Minor Edit for Grammar.

The linker complains about multiple definitions, not declarations.
If you need to use a symbol (for instance a variable) in multiple sources then you have to:
  • Define it in one, single source.
  • Declare it, as extern in all the other sources (you may include an header file for the purpose).



e.g.:

header file decl.h
#ifndef _DECL_H_
#define _DECL_H_
/* global symbol declarations */
extern int global_counter;
/*...*/
#endif


source file src1.c
/* global symbol definition */
int global_counter; 
/*...*/


source file src2.c
#include "decl.h"

/* use the global symbol */
int increment()
{
  global_counter++;
}
/*...*/


and so on...

:)
 
Share this answer
 
Simply put this in your ADeclaration.h to avoid multiple inclusions:
#ifndef ADECLARATION_H
#define ADECLARATION_H

 // Contents of ADeclaration.h 

#endif


Good luck!
 
Share this answer
 
v2
Comments
Dalek Dave 13-Oct-10 4:46am    
Good Call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900