# Generating a class dictionary with C++ namespaces

**URL:** <https://root-forum.cern.ch/t/generating-a-class-dictionary-with-c-namespaces/22062>\
**Category:** ROOT\
**Created:** [October 17, 2016, 11:15pm UTC](https://root-forum.cern.ch/t/generating-a-class-dictionary-with-c-namespaces/22062 "2016-10-17T23:15:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremym](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/58f4c7/32.png) [@jeremym](https://root-forum.cern.ch/u/jeremym)\
**Post date:** [October 17, 2016, 11:15pm UTC](https://root-forum.cern.ch/t/generating-a-class-dictionary-with-c-namespaces/22062/1 "2016-10-17T23:15:23Z")

</div>

Hi,

I’m attempting to generate a ROOT dictionary with some code that uses namespaces.

My header is basically like this:

```auto
namespace event {

class Event: public TObject {
    // ....
    ClassDef(Event, 1);
};
}
```

The header seems to be processed fine, but I get an issue with the corresponding source file:

```auto
#include "Event/Event.h"
namespace event {
ClassImp(Event)
}
```

I get this error message:

```auto
[1151 $] make install
[1%] Building CXX object Event/CMakeFiles/Event.dir/src/Event.cxx.o
In file included from /nfs/slac/g/ldmx/software/root/root-6.06.08-build/include/TObject.h:31:0,
                 from /u/ey/jeremym/ldmx-dev/ldmx-sw/Event/include/Event/Event.h:5,
                 from /u/ey/jeremym/ldmx-dev/ldmx-sw/Event/src/Event.cxx:1:
/nfs/slac/g/ldmx/software/root/root-6.06.08-build/include/Rtypes.h:272:7: error: ‘TGenericClassInfo’ does not name a type
       TGenericClassInfo *GenerateInitInstance(const name*); \
       ^
/nfs/slac/g/ldmx/software/root/root-6.06.08-build/include/Rtypes.h:279:24: note: in expansion of macro ‘ClassImpUnique’
 #define ClassImp(name) ClassImpUnique(name,default)
                        ^
/u/ey/jeremym/ldmx-dev/ldmx-sw/Event/src/Event.cxx:7:1: note: in expansion of macro ‘ClassImp’
 ClassImp(Event)
 ^
/nfs/slac/g/ldmx/software/root/root-6.06.08-build/include/Rtypes.h:275:44: error: ‘GenerateInitInstance’ was not declared in this scope
             GenerateInitInstance((name*)0x0)->SetImplFile( __FILE__ , __LINE__ ); \
                                            ^
/nfs/slac/g/ldmx/software/root/root-6.06.08-build/include/Rtypes.h:279:24: note: in expansion of macro ‘ClassImpUnique’
 #define ClassImp(name) ClassImpUnique(name,default)
                        ^
/u/ey/jeremym/ldmx-dev/ldmx-sw/Event/src/Event.cxx:7:1: note: in expansion of macro ‘ClassImp’
 ClassImp(Event)
 ^
make[2]: *** [Event/CMakeFiles/Event.dir/src/Event.cxx.o] Error 1
make[1]: *** [Event/CMakeFiles/Event.dir/all] Error 2
make: *** [all] Error 2
```

I am using the following CMake to do this:

```auto
ROOT_GENERATE_DICTIONARY(EventDict ${Event_INCLUDE_DIR}/Event/Event.h MODULE ${PROJECT_NAME} LINKDEF ${Event_INCLUDE_DIR}/Event/EventLinkDef.h)
```

And I have this link def:

```auto
#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclass;
#pragma link C++ nestedtypedef;

#pragma link C++ namespace event;
#pragma link C++ defined_in namespace event;
#pragma link C++ class event::Event+;

#endif
```

It seems quite similar to this old thread pertaining to ROOT5.

[url][Trying to compile rootcint dictionary with namespaces](https://root-forum.cern.ch/t/trying-to-compile-rootcint-dictionary-with-namespaces/14562/1)

Am I missing something simple here that is causing this to fail?

Also, is there an example of creating a ROOT dictionary using namespaces someplace? This seems like it would be very handy.

Thanks!

–Jeremy

---

<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:** [October 18, 2016, 5:32am UTC](https://root-forum.cern.ch/t/generating-a-class-dictionary-with-c-namespaces/22062/2 "2016-10-18T05:32:31Z")

</div>

> [@Adding a class: hand holding requested](https://root-forum.cern.ch/t/adding-a-class-hand-holding-requested/13893/2):
>
> On Linux, try (for MacOS and/or Windows, you need to find someone who can “transform” the commands given below): `root-config --cxx --cflags` -fPIC -c MyClass.cxx rootcint -f MyClass\_Dict.cxx -c -p MyClass.hxx MyClass\_LinkDef.h `root-config --cxx --cflags` -fPIC -c MyClass\_Dict.cxx `root-config --cxx --cflags` -fPIC -shared -o libMyClass.so MyClass.o MyClass\_Dict.o The easiest way to try it is: root [0] .L libMyClass.so root [1] .Class MySpace::MyClass1 root [2] .Class std::vector\< MySpace::M…

> [@Trying to compile rootcint dictionary with namespaces](https://root-forum.cern.ch/t/trying-to-compile-rootcint-dictionary-with-namespaces/14562/2):
>
> On Linux, try (for MacOS and/or Windows, you need to find someone who can “transform” the commands given below): `root-config --cxx --cflags` -W -Wall -fPIC -c TestInfo.cxx rootcint -f TestInfo\_Dict.cxx -c -p TestInfo.h TestInfo\_LinkDef.h `root-config --cxx --cflags` -W -Wall -fPIC -c TestInfo\_Dict.cxx `root-config --cxx --cflags` -W -Wall -fPIC -shared -o libTestInfo.so TestInfo.o TestInfo\_Dict.o `root-config --glibs` Note: I didn’t fix the two problems in the “TestInfo.cxx” which are reported …

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [October 18, 2016, 6:42am UTC](https://root-forum.cern.ch/t/generating-a-class-dictionary-with-c-namespaces/22062/3 "2016-10-18T06:42:56Z")

</div>

Basically you need to put the ClassImp outside the namespace.

```auto
#include "Event/Event.h"

ClassImp(event::Event);

namespace event {
...
}
```

---

<div class="post-metadata">

**Author:** ![jeremym](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/58f4c7/32.png) [@jeremym](https://root-forum.cern.ch/u/jeremym)\
**Post date:** [October 18, 2016, 6:30pm UTC](https://root-forum.cern.ch/t/generating-a-class-dictionary-with-c-namespaces/22062/4 "2016-10-18T18:30:13Z")

</div>

[quote=“mato”]Basically you need to put the ClassImp outside the namespace.

[code]  
#include “Event/Event.h”

ClassImp(event::Event);

namespace event {  
…  
}  
[/code][/quote]

Great. I figured it was something basic. ![8)](https://root-forum.cern.ch/uploads/default/original/1X/fe5f42ae79e389360ae9d969db4dcc4bca03d384.gif "Cool")

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [October 18, 2016, 7:50pm UTC](https://root-forum.cern.ch/t/generating-a-class-dictionary-with-c-namespaces/22062/5 "2016-10-18T19:50:04Z")

</div>

Hi Jeremy,

I am not sure it’s your case but perhaps it should be noted also that ClassImp is necessary only if you plan to use THtml for generating documentation for your classes.

Cheers,  
Danilo
