Re: [ROOT] Error: multiple definitions

From: Justin Findlay (findlay@cosmic.utah.edu)
Date: Mon Dec 15 2003 - 07:53:47 MET


On Mon Dec 15 2003 - 00:26:00 MET cstrato wrote:

> In the header file XPSApp.h I have defined:
>     const char *kXPSName = "This is text";
> //or:  static const char *kXPSName = "This is text";
>
> In a couple of source files I "#include XPSApp.h" Sorrowly, at the end
> of the compilation I get the error:
>
> ld: multiple definitions of symbol _kXPSName XDataFrame.o definition of
> _kXPSName in section (__DATA,__data) XPSApp.o definition of _kXPSName in
> section (__DATA,__data) make: *** [XPSApp] Error 1
>
> Do you know how I can define kXPSName so that I can use it in multiple
> source files?

This may be your problem, forgive me if it is not.  Tell the preprocessor
to include your header once only by adding the following lines to your
header file (every header file you ever happen to write).

$ cat XPSApp.h
#ifndef _XPSAPP_H_
#define _XPSAPP_H_

//code...
//...

#endif //_XPSAPP_H_

What this means to the preprocessor is "if the following code has been
included already, don't include it again".  The preprocessor browses
through the source code and notes this conditional definition (lines
beginning with `#' actuate preprocessor activity) in your hapless header
file.


Justin



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:17 MET