RE: [ROOT] Multiple definition of member function?

From: Philippe Canal (pcanal@fnal.gov)
Date: Wed Aug 06 2003 - 20:28:39 MEST


Hi Chris,

When you do:
	rootcint -f dict.cxx -c Chambers.cxx LinkDef.h
the file pass in argument (here 'Chambers.cxx') is #include in the
dictionary.  In particular this means that If you do
	g++ dict.cxx Chambers.cxx ....
The file Chambers.cxx is compiled twice.

So in your case you should actually call:
	rootcint -f dict.cxx -c Chambers.h LinkDef.h

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Chris Hayward
Sent: Wednesday, August 06, 2003 12:44 PM
To: ROOT Talk Mailing List
Subject: [ROOT] Multiple definition of member function?


Hello,
I am using ROOT 3.05/07 with gcc 2.96 on lxplus. I have defined a class
with member functions that are for the most part defined in-line. However,
I do have one defined in my .cxx file. This function has caused me to get
the following error when trying to compile:

/tmp/ccPP4bRM.o: In function `Chamber::CalculateMeans(void)':
/tmp/ccPP4bRM.o(.text+0x0): multiple definition of
`Chamber::CalculateMeans(void)'
/tmp/cccSwL9F.o(.text+0x0): first defined here
/tmp/ccGXmfh0.o: In function `Chamber::CalculateMeans(void)':
/tmp/ccGXmfh0.o(.text+0x0): multiple definition of
`Chamber::CalculateMeans(void)'
/tmp/cccSwL9F.o(.text+0x0): first defined here
collect2: ld returned 1 exit status

However, it works fine when I interpret the code in interactive mode. I
have tried to follow the Event example, but I still cannot get it to work.
The relevant parts of the header and implementation are below.

Thank you in advance for your help,
Chris

Chamber.h:

    Chamber() { //here the constructor is defined}
   ~Chamber() {};               //default destructor
    void CalculateMeans();

//below are a bunch of getters and setters that worked fine before I added
//Calculate Means


Chamber.cxx:

#include "/afs/cern.ch/user/x/xtomo/SoftWare/chris/Chamber.h"

//needed for ROOT I/O
ClassImp(Chamber);

void Chamber::CalculateMeans()

{ //here is the function. error occurs even with empty brackets. }


#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################



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