# Trying to compile rootcint dictionary with namespaces

**URL:** <https://root-forum.cern.ch/t/trying-to-compile-rootcint-dictionary-with-namespaces/14562>\
**Category:** ROOT\
**Created:** [July 11, 2012, 2:05pm UTC](https://root-forum.cern.ch/t/trying-to-compile-rootcint-dictionary-with-namespaces/14562 "2012-07-11T14:05:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahler](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mahler](https://root-forum.cern.ch/u/mahler)\
**Post date:** [July 11, 2012, 2:05pm UTC](https://root-forum.cern.ch/t/trying-to-compile-rootcint-dictionary-with-namespaces/14562/1 "2012-07-11T14:05:06Z")

</div>

Hi, I’m trying to compile a dictionary generated by rootcint, and I’m running into some weird errors.

The sources I’m compiling are:

TestInfo.h

[code]namespace TestInfo  
{  
class TestClass;

std::vector Func(float num,int N);

class TestClass : public TObject  
{  
public:  
TestClass(float i=0);  
TestClass(const TestClass& in);  
TestClass& operator=(const TestClass& in);  
~TestClass() {}

```
  const int& i() {return this->index;}

private:
  int index;

ClassDef(TestClass,1);

```

};  
};[/code]

TestInfo.cxx

[code]#include “TObject.h”  
#include “TestInfo.h”

namespace TestInfo  
{  
ClassImp(TestClass)

TestClass::TestClass(float i)  
{  
this-\>index = i;  
}

TestClass::TestClass(const TestClass& in)  
{  
this-\>index = in.index;  
}

TestClass& TestClass::operator=(const TestClass& in)  
{  
this-\>index = in.index;  
}

std::vector Func(float num,int N)  
{  
std::vector answer;  
for(int i=0;i\<N;i++)  
{  
answer.push\_back(TestClass(num));  
}  
return answer;  
}  
};[/code]

And I have the following LinkDef  
TestInfo\_LikeDef.h

[code]#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 TestInfo;

#pragma link C++ defined\_in namespace TestInfo;

#pragma link C++ class TestInfo::TestClass+;

#endif[/code]

if you put them all in the same directory, I do the following:

```auto

```

which seems fine, and builds the files TestInfo\_Dict.cxx and TestInfo\_Dict.h.

I now try to compile these, with:

```auto

```

And I get the following load of errors:

`In file included from TestInfo_Dict.h:34:0,
                 from TestInfo_Dict.cxx:17:
TestInfo.cxx:6:3: error: ‘TGenericClassInfo’ does not name a type
TestInfo.cxx:6:3: error: ‘GenerateInitInstance’ was not declared in this scope
TestInfo_Dict.cxx: In function ‘int G__TestInfo_Dict_107_0_1(G__value*, const char*, G__param*, int)’:
TestInfo_Dict.cxx:218:17: error: ‘TestClass’ was not declared in this scope
TestInfo_Dict.cxx:218:17: note: suggested alternative:
TestInfo.h:7:9: note: ‘TestInfo::TestClass’
TestInfo_Dict.cxx:218:26: error: template argument 1 is invalid
TestInfo_Dict.cxx:218:26: error: template argument 2 is invalid
TestInfo_Dict.cxx:218:33: error: invalid type in declaration before ‘;’ token
TestInfo_Dict.cxx:219:26: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’
TestInfo_Dict.cxx:219:26: error: expected a type, got ‘TestClass’
TestInfo_Dict.cxx:219:26: error: template argument 2 is invalid
TestInfo_Dict.cxx:219:33: error: invalid type in declaration before ‘=’ token
TestInfo_Dict.cxx:219:111: error: cannot convert ‘std::vector<TestInfo::TestClass>’ to ‘int’ in initialization
TestInfo_Dict.cxx:220:37: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’
TestInfo_Dict.cxx:220:37: error: expected a type, got ‘TestClass’
TestInfo_Dict.cxx:220:37: error: template argument 2 is invalid
TestInfo_Dict.cxx: In function ‘void G__setup_memfuncTestInfo()’:
TestInfo_Dict.cxx:525:73: error: ‘TestClass’ was not declared in this scope
TestInfo_Dict.cxx:525:73: note: suggested alternative:
TestInfo.h:7:9: note: ‘TestInfo::TestClass’
TestInfo_Dict.cxx:525:82: error: template argument 1 is invalid
TestInfo_Dict.cxx:525:82: error: template argument 2 is invalid
TestInfo_Dict.cxx:525:63: error: expected primary-expression before ‘(’ token
TestInfo_Dict.cxx:525:86: error: expected primary-expression before ‘)’ token
TestInfo_Dict.cxx:525:88: error: expected primary-expression before ‘float’
TestInfo_Dict.cxx:525:95: error: expected primary-expression before ‘int’`

If I take out the ClassDef and ClassImp from TestInfo.cxx and TestInfo.h, and run `g++ -I$ROOTSYS/include -c TestInfo.cxx -o TestInfo.o`, It compiles fine so my code is definitely legal C++, however I’d like to draw your attention to this set of errors in particular:

`In file included from TestInfo_Dict.h:34:0,
                 from TestInfo_Dict.cxx:17:
TestInfo.cxx:6:3: error: ‘TGenericClassInfo’ does not name a type
TestInfo.cxx:6:3: error: ‘GenerateInitInstance’ was not declared in this scope
TestInfo_Dict.cxx: In function ‘int G__TestInfo_Dict_107_0_1(G__value*, const char*, G__param*, int)’:
TestInfo_Dict.cxx:218:17: error: ‘TestClass’ was not declared in this scope
TestInfo_Dict.cxx:218:17: note: suggested alternative:`

Is there a header I’m forgetting to include for TGenericClassInfo?  
And why doesn’t rootcint encose the function G\_\_TestInfo\_Dict\_107\_0\_1 in my namespace like it’s supposed to? If it enclosed with the proper namespace, there wouldn’t be a problem.

I’m using root v5.34.00

---

<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:** [July 11, 2012, 5:01pm UTC](https://root-forum.cern.ch/t/trying-to-compile-rootcint-dictionary-with-namespaces/14562/2 "2012-07-11T17:01:54Z")

</div>

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 by the compiler. I didn’t want to take all the fun away from you!

The easiest way to try it is: `root [0] .L libTestInfo.so
root [1] .Class TestInfo
root [2] .Class TestInfo::TestClass
root [3] .Class std::vector<TestInfo::TestClass>`  
Make sure you read also this thread: [url][Adding a class: hand holding requested](https://root-forum.cern.ch/t/adding-a-class-hand-holding-requested/13893/1)  
[TestInfo.h](https://root-forum.cern.ch/uploads/default/original/2X/9/97d0fdab3a26cda3f3bae1a9390f318225c51590.h) (472 Bytes)  
[TestInfo.cxx](https://root-forum.cern.ch/uploads/default/original/2X/e/ead95bd8e9fbd90eaad095286926377eba822f20.cxx) (534 Bytes)  
[TestInfo\_LinkDef.h](https://root-forum.cern.ch/uploads/default/original/2X/4/459172a0000cce26042911ecd1b0e02df5d07ed9.h) (396 Bytes)

---

<div class="post-metadata">

**Author:** ![DanielGr](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danielgr/32/13682_2.png) [@DanielGr](https://root-forum.cern.ch/u/DanielGr)\
**Post date:** [September 18, 2017, 3:16pm UTC](https://root-forum.cern.ch/t/trying-to-compile-rootcint-dictionary-with-namespaces/14562/3 "2017-09-18T15:16:57Z")

</div>

I’ve encountered this same error now and found a solution to the compiler errors. For anyone else encountering it, the solution is to call `ClassImp` outside of your namespace. For the example above:

```cpp
ClassImp(TestInfo::TestClass)
namespace TestInfo
{
    TestClass:TestClass(float i)
    ...

```
