Compiling own classes with ACLiC gives error

Hey Root-Experts,

I have a question about how to compile several own classes with ACLiC or better to say I don’t see how to solve my issue.

I have several own classes with their own *.h and *.cc files and a final *.cc script (which also has a declaration *.h file) where some stuff is executed then. I’m using the root compiler for this by executing a little makro file which looks like this:

{
    gSystem->Load("libRooFit");
    gROOT->ProcessLine(".L classA.cc+");
    gROOT->ProcessLine(".L classB.cc+");
    gROOT->ProcessLine(".L executer.cc+");
    gROOT->ProcessLine("executer()");
}

In principle everything works fine but with one exception.
In my classB I want do declare a member variable of the type of a pointer to classA. Thus I include classA in the header of classB. Nevertheless this doesn’t work and I get an error:

In file included from /user/somePath/executer.h:39:
/user/somePath/classB.h:84:17: error: use of undeclared identifier 'classA'
    classA* a;
    ^
/user/somePath/classB.h:84:30: error: expected expression
    classA* a;
           ^
Error in <ACLiC>: Dictionary generation failed!

In my understanding how c++ source code gets compiled this should work and I dont see the problem here.

It would be great if anyone could give me a hint.
If you need a more detailed description of my exact source code and the error messages I can provide it of course.

Thanks and best

In your “classB.h”, you should have: #include "classA.h" or at least (this should be sufficient if you only need a “pointer”): class classA;

Hi Pepe,
thanks for your answer. Thats exactly what I do: including classA.h in classB.h.

The problem still exists, which is a strange behaviour for me…

Try: classA *a;

I’m sorry but I think I don’t understand what you mean. The line

is exactly what I do. So in general in my classB.h I have something like

#include "classA.h"

classB {

public:
	classB();
	inline virtual ~classB() {}

	classA *a = NULL; // null pointer not nescessary, doesnt change anything
	
	ClassDef(classB, 1)
};

If you are using ROOT 5, try to rename “classA” into “myclassA” or simply “A” (it seems to me that CINT and/or rootcint think that “classA” means “class A” or something like this).

In reality, the class names are different; think of those classes to be named “TTemplateFit.h” (classA) and “TAuxiliary.h” (classB)

This shouldn’t be a problem then, or does it?

I guess you need to provide the whole source code which is needed to reproduce your problem.

BTW. Double check the line 83 in classB.h -> if there is any mistake, the compiler may generate a strange error in line 84.

Thanks a lot for your effort.
I attached some version of my complete code (includes 8 source files) with all the original “includes” an so on; I only shortened the classes to some example stuff which doesn’t affect the problem, for better readability.

If one now runs “root -l run_rooFit” (in run_rooFit the compile commands are listed), everything works fine (all the code compiles).
But if one now changes in TAuxiliary.h in line 42 from

//~ map<string, TTemplateFit*> tf;

to

map<string, TTemplateFit*> tf;

so that there is a pointer instance of a TTemplateFit object, the error I mentioned in the opener occurs.
The header for the TTemplateFit objects is included in the upper headerfile rooFitHeader.h - but the problem is still there if one includes TTemplateFit directly in TAuxiliary.

Maybe there is some stupid mistake in there… would be great if you could check it out, I’m sorry for this extensive problem, hopefully it’s not too confusing.
classProblem.tar (20 KB)

  1. You need to get rid of circular dependencies in your “#include” files.
  2. “ClassDef” must always be the “very last” and “public” (see also [root.cern.ch/phpBB3/viewtopic.ph … 767#p51767](Simple way to create and merge shared libraries? for some additional neat Philippe’s notes concerning “ClassDef” / “ClassImp” / “TObject inheritance”).
  3. You should create dictionary entries for additional containers that you define.
    NoClassProblem.tar.gz (2.31 KB)

Hi Pepe,

thanks a lot for your clarification! You really helped me a lot, I’ve been stuck on this for a few days now :smiley:

I know that the coding and #including is a bit (or very) ugly but I didn’t expect it to cause such problems, due to the #define-stuff I thought it would be ok… well ok I will try to improve my coding with respect to the points you mentioned.

Thanks again for solving this!

Maybe I can ask you another little question somehow related to this:

Since I shortened the code, it is not nescessary in the code that you corrected. But in my original classes TAuxiliary and TTemplateFit both contain a bunch of methods using several ROOT classes like TFile, TH1F and so on. In other words, thats the reason why both included the rooFitHeader.h where all those root classes are imported.

How do I do this, including all those stuff in both classes, without circular includings?

Add appropriate “minimal required set” of ROOT “#include” files to TTemplateFit and TAuxiliary (e.g. like I did with “Rtypes.h” for “ClassDef” and “ClassImp”). You don’t need to worry about circular includes for ROOT classes.