Dictionaries for STL objects

Hi all,
I have found some posts in the forum dealing with CINT dictionaries & STL object, but I still have the following problem: using this test example:

File Calib.h :

#include <stdio.h>
#include <TNamed.h>

#include <vector>
using namespace std;

class Calib: public TNamed{
 public:
  Calib(){};

  vector<Calib*> calibs;

  ClassDef(Calib,1);
};


#if defined __MAKECINT__ || defined __CINT__
#pragma link C++ class vector<Calib*>+;
#endif

File Calib.cxx:

#include "Calib.h"
ClassImp(Calib);

I am trying to have it working with its dictionaries: using directly the root prompt it works (in 5.22 but not in 5.17 but it’s fine):

.L Calib.cxx++
Calib c
printf("%d\n", c.calibs.size());
(int)0

everything works (NOTE: it seems that the #pragma is needed)

When i try with a makefile it doesn’t seem to work:

g++ -pthread -m32 -I/usr/local/root/include -I. -Wall -O3  Calib.cxx -c -o Calib.o

rootcint -f Calib.CintDictionary.cxx -c -pthread -m32 -I/usr/local/root/include -I. -Wall -O3  Calib.h

g++ -pthread -m32 -I/usr/local/root/include -I. -Wall -O3  Calib.CintDictionary.cxx -c -o Calib.CintDictionary.o

g++ -shared Calib.o Calib.CintDictionary.o -o Calib.so

root
.L Calib.so
Calib c
printf("%d\n", c.calibs.size());

Error: Can't call vector<Calib*,allocator<Calib*> >::size() in current scope (tmpfile):1:
Possible candidates are...
(in vector<Calib*,allocator<Calib*> >)

do you have any clue?

thank you!
Luigi

(using ROOT 5.22/00 (trunk@26997, Jan 20 2009, 14:20:00 on linux)

Hi,

You need to write a linkdef file. When you userootcint -f Calib.CintDictionary.cxx -c ... Calib.ha default linkdef file is use containing (in your case);#ifdef __CINT__ #pragma link off all globals; #pragma link off all classes; #pragma link off all functions; #pragma link C++ class Calib; // Name of the .h file without the extension. #endif. In particular the link off all classes ‘erases’ the #pragma you have the .h file. You need a linkdef.h file containing:#ifdef __CINT__ #pragma link C++ class Calib+; #endifand add it to the rootcint line:rootcint -f Calib.CintDictionary.cxx -c ... Calib.h CalibLinkDef.h

Cheers,
Philippe

Hi Philippe,
thank you for the reply.
Now it works :smiley:, either by writing the linkdef file as you suggested or by creating an empty linkdef file (to avoid the creation of the default linkdef file 8) ) and putting all the #pragmas into the .h

By the way, in order to work a bit with the iterators, I had to add:

#pragma link C++ class Calib+;

#pragma link C++ class vector<Calib*>;
#pragma link C++ class vector<Calib*>::iterator;
#pragma link C++ function operator != ( vector<Calib*>::iterator, vector<Calib*>::iterator);

so that a command like:

for(vector<Calib*>::iterator i=c.calibs.begin();i!=c.calibs.end();++i) 
     /* something */

is correctly interpreted.

Thank you!
Luigi