# Compiling own classes with ACLiC gives error

**URL:** <https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634>\
**Category:** ROOT\
**Created:** [August 1, 2016, 4:10pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634 "2016-08-01T16:10:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralf\_rwth](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@ralf\_rwth](https://root-forum.cern.ch/u/ralf_rwth)\
**Post date:** [August 1, 2016, 4:10pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/1 "2016-08-01T16:10:14Z")

</div>

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:

```auto
{
    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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [August 1, 2016, 4:42pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/2 "2016-08-01T16:42:34Z")

</div>

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;`

---

<div class="post-metadata">

**Author:** ![ralf\_rwth](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@ralf\_rwth](https://root-forum.cern.ch/u/ralf_rwth)\
**Post date:** [August 1, 2016, 4:53pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/3 "2016-08-01T16:53:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [August 1, 2016, 5:00pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/4 "2016-08-01T17:00:26Z")

</div>

Try: `classA *a;`

---

<div class="post-metadata">

**Author:** ![ralf\_rwth](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@ralf\_rwth](https://root-forum.cern.ch/u/ralf_rwth)\
**Post date:** [August 1, 2016, 5:12pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/5 "2016-08-01T17:12:05Z")

</div>

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

```auto

```

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

```auto
#include "classA.h"

classB {

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

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

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [August 1, 2016, 5:40pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/6 "2016-08-01T17:40:50Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![ralf\_rwth](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@ralf\_rwth](https://root-forum.cern.ch/u/ralf_rwth)\
**Post date:** [August 1, 2016, 5:51pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/7 "2016-08-01T17:51:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [August 1, 2016, 6:00pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/8 "2016-08-01T18:00:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ralf\_rwth](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@ralf\_rwth](https://root-forum.cern.ch/u/ralf_rwth)\
**Post date:** [August 2, 2016, 9:26am UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/9 "2016-08-02T09:26:39Z")

</div>

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

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

to

```auto
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](https://root-forum.cern.ch/uploads/default/original/2X/9/95d1c510b497ccc78b03891bc36b8d9805413b8e.tar) (20 KB)

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [August 2, 2016, 11:12am UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/10 "2016-08-02T11:12:44Z")

</div>

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?](https://root-forum.cern.ch/t/simple-way-to-create-and-merge-shared-libraries/11652/6) 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](https://root-forum.cern.ch/uploads/default/original/2X/4/4973ae52990d51ffac5ab0079267d5b8cd01fe69.gz) (2.31 KB)

---

<div class="post-metadata">

**Author:** ![ralf\_rwth](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@ralf\_rwth](https://root-forum.cern.ch/u/ralf_rwth)\
**Post date:** [August 2, 2016, 12:05pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/11 "2016-08-02T12:05:01Z")

</div>

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 😃

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!

---

<div class="post-metadata">

**Author:** ![ralf\_rwth](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/e8c25b/32.png) [@ralf\_rwth](https://root-forum.cern.ch/u/ralf_rwth)\
**Post date:** [August 2, 2016, 12:18pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/12 "2016-08-02T12:18:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [August 2, 2016, 1:34pm UTC](https://root-forum.cern.ch/t/compiling-own-classes-with-aclic-gives-error/21634/13 "2016-08-02T13:34:35Z")

</div>

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.
