I have a problem compiling via Makefile two TObject-derived classes whose code shares the same class: I get
MySecondClass_Dict.o: In function `TheCommonClass::Class_Name()':
MySecondClass_Dict.C:(.text+0x0): multiple definition of `TheCommonClass::Class_Name()'
MyFirstClass_Dict.o:MyFirstClass_Dict.C:(.text+0x0): first defined here
// etc for other methods of TheCommonClass
which makes me think I am not dealing correctly with dictionaries.
My code structure is
[ul]
[li]NtupleReader, a TObject-derived class which loops over a TTree containing TClonesArrays;
[/li]
[li]MyFirstClass, daughter of NtupleReader (performs one analysis);
[/li]
[li]MySecondClass, daughter of NtupleReader (performs another analysis), sharing the TObject TheCommonClass with MyFirstClass [size=85](this object is not logically common to all >2 analyses, so I do not define it in the common parent)[/size];
[/li]
[li]theAnalysisRunner, a simple C++ main which calls one of the two analyses depending on user’s choice.[/li][/ul]
I have two LinkDef files for the daughter classes,
[code]// LinkDef_MyFirstClass.h ::: LinkDef_MySecondClass.h
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclass;
#pragma link C++ class TheCommonClass+;
#pragma link C++ class MyFirstClass+; // in the first file only
#pragma link C++ class MySecondClass+; // in the second file only
#endif // CINT
[/code]
one for the parent class
[code]// LinkDef_NtupleReader.h
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclass;
#pragma link C++ class Muon+; // this and many other TObject-derived classes stored in TClonesArrays (I omit them for the sake of clarity)
#pragma link C++ class NtupleReader+;
#endif // CINT
[/code]
and in the Makefile I do
[code]// Makefile
CC = g++
CFLAGS = -Wall -c
ROOTFLAG = ${ROOTSYS}/bin/root-config --cflags --libs
DICTEXEC = ${ROOTSYS}/bin/root-config --exec-prefix
/bin/rootcint
theAnalysisRunner: theAnalysisRunner.o MyFirstClass.o MySecondClass.o NtupleReader.o TheCommonClass.o Muon.o NtupleReader_Dict.o MyFirstClass_Dict.o MySecondClass_Dict.o
$(CC) -Wall $^ $(ROOTFLAG) -o $@
NtupleReader_Dict.C: NtupleReader.h Muon.h LinkDef_NtupleReader.h
$(DICTEXEC) -f $@ -c -p $^
MyFirstClass_Dict.C: MyFirstClass.h NtupleReader.h TheCommonClass.h LinkDef_MyFirstClass.h
$(DICTEXEC) -f $@ -c -p $^
MyFirstClass_Dict.C: MySecondClass.h NtupleReader.h TheCommonClass.h LinkDef_MySecondClass.h
$(DICTEXEC) -f $@ -c -p $^
.SUFFIXES: .C .o
.C.o:
$(CC) $(CFLAGS) -o $@ $< root-config --cflags
[/code]
What am I doing wrong? Actually if I merge the two dictionaries for the derived classes everything is okay, but I would prefer to keep the development of the two analyses completely separated.