MakeClass Include Guards

Hi, I recently had a problem when trying to run my old script (that ran fine with ROOT 5.34) under ROOT6. The error was when compiling certain files, and it complained of redefinitions of class methods, but the “previous definition” was listed as being the same line in the same file as the “redefinition”.

The error messages looked like this:

In file included from /Users/jfcaron/Projects/Proto2BeamTest2/MydaqT.C:4: ./daqT.h:86:7: error: redefinition of 'daqT' daqT::daqT(TTree *tree) : fChain(0) ^ ./daqT.h:86:7: note: previous definition is here daqT::daqT(TTree *tree) : fChain(0) ^ In file included from input_line_238:14: In file included from /Users/jfcaron/Projects/Proto2BeamTest2/MydaqT.C:4: ./daqT.h:101:7: error: redefinition of '~daqT' daqT::~daqT() ^ ./daqT.h:101:7: note: previous definition is here daqT::~daqT() ^ In file included from input_line_238:14: In file included from /Users/jfcaron/Projects/Proto2BeamTest2/MydaqT.C:4: ./daqT.h:107:13: error: redefinition of 'GetEntry' Int_t daqT::GetEntry(Long64_t entry) ^ ./daqT.h:107:13: note: previous definition is here Int_t daqT::GetEntry(Long64_t entry) ^

I tracked down the problem to the auto-generated include guards in my daqT.h and daqT.C files that were auto-generated using MakeClass. Here’s the rough structure:

daqT.h:

#ifndef daqT_h
#define daqT_h

// some includes

class daqT {
  // lots of class members...
};
#endif

// What's this?
#ifdef daqT_cxx
// A bunch of implementation code (remember this is the .h file)
#endif // #ifdef daqT_cxx

Then in the daqT.C file:

#define daqT_cxx
#include "daqT.h"
// ...

Why does MakeClass do it this way? What’s the purpose of the daqT_cxx flag? Normally you put your include guards around the WHOLE header file, not just the top bits. My fix was to remove the daqT_cxx flag and make the first #ifdef in the .h apply to the whole file, not just the class declaration part.

More confusingly, why did it only break when moving to root 6.00.00? I was using a recent clang++ for compilation even under root 5.34, so is this a cint/rootcint thing? If it’s a bug, I’d like to report it, but I don’t know why MakeClass does this in the first place.

Jean-François