Trying to compile rootcint dictionary with namespaces

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:

which seems fine, and builds the files TestInfo_Dict.cxx and TestInfo_Dict.h.

I now try to compile these, with:

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

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
TestInfo.h (472 Bytes)
TestInfo.cxx (534 Bytes)
TestInfo_LinkDef.h (396 Bytes)

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:

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