My TObject derived class cannot use std::vector in cxx

I’m finding this error when using my class which is derived from TOBject. Below the description of the class:

In myClass.h:

#ifdef CINT
#pragma link C++ class vector+;

class myClass : public TObject {
myClass(const vector& UserData);
ClassDef(myClass, 1)

in myClass.cxx I have:

#include “myClass.h"
myClass:myClass(const vector& UserData){


I create the dictionaries, compile all (myClass.cxx is compiled and added in a so library) and then try to use the library, but when linking I have this error:

Undefined symbols for architecture x86_64:
“myClass::myClass(std::vector<double, std::allocator > const&)", referenced from:
EventSelection::isThereATrueParticle(float, float, float, float, float, float, float, float, float&, float&, float&) in EventSelection.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

This does happen to any method that used std::vector, not to others.
This does happen only if the implementation of the method (in this case the constructor) is in the .cxx file. If the same code is implemented in myClass.h then the error disappears.
I tried to add the #pragma command in the header file, but this does not cure. I also tried to add the #pragma command in LinkDef.h file and add it in the cint command, but it says :

Note: Link requested for already precompiled class vector<double,allocator > (ignore this message) :0:

So I think the dictionary is ready to use vectors, but do not link it correctly.
Can you suggest how to implement it?


I just tried a little stupid thing:


#include "TObject.h"

class vec : public TObject{
   vec(vector <double>& v); 


#include "vec.h"

vec::vec(vector<double>&v){printf("hello from vec\n");}


CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x vec.cxx
(const class vec)140615958957088
root [1] vector<double> c
root [2] vec b(c)
hello from vec
root [3] 

So in that context it seems to work …

Hi Olivier,
I found indeed that no templated objects can be used in the TOBjects, as written in: … t-classdef

So I found the trick to not to have the templated vector as argument in the .cxx, and it seems to solve the problem.

So I did same the vector as parameter of the class and did this:

in MyClass.h
MyClass(vector vec) {myvec=vec; doOtherwithVec()};

in MyClass.cxx:

use my vector…

Thanks a lot for your help/suggestions!