Compiling a RooFit User Pdf with g++

Hi all,

I have created a RooAbsPdf via the class factory method using the example shown at … ory.C.html.

I can compile the source files it produces with ROOT via

but with g++ command,

I receive the error,

usr/lib/../lib64/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' /tmp/dvoong/ccty6oh4.o: In function `__static_initialization_and_destruction_0(int, int)': MyPdfV1.cxx:(.text+0x2da): undefined reference to `ROOT::GenerateInitInstance(MyPdfV1 const*)' /tmp/dvoong/ccty6oh4.o: In function `MyPdfV1::IsA() const': MyPdfV1.cxx:(.text._ZNK7MyPdfV13IsAEv[MyPdfV1::IsA() const]+0x13): undefined reference to `MyPdfV1::Class()' /tmp/dvoong/ccty6oh4.o:(.rodata._ZTV7MyPdfV1[vtable for MyPdfV1]+0x1d0): undefined reference to `MyPdfV1::ShowMembers(TMemberInspector&)' /tmp/dvoong/ccty6oh4.o:(.rodata._ZTV7MyPdfV1[vtable for MyPdfV1]+0x1d8): undefined reference to `MyPdfV1::Streamer(TBuffer&)' /tmp/dvoong/ccty6oh4.o:(.rodata._ZTV7MyPdfV1[vtable for MyPdfV1]+0x630): undefined reference to `non-virtual thunk to MyPdfV1::ShowMembers(TMemberInspector&)' /tmp/dvoong/ccty6oh4.o:(.rodata._ZTV7MyPdfV1[vtable for MyPdfV1]+0x638): undefined reference to `non-virtual thunk to MyPdfV1::Streamer(TBuffer&)' collect2: ld returned 1 exit status

I’ve tried to include various headers and libraries to the compiler but with no avail. Any idea what the issue is?

I am using,



gcc version 4.6.3 (GCC)



I like to do the same for my custom PDF. Did anyone ever got an answer to this question?


Hi Wing,

I eventually found out how to do it. For a user class called MyRooPdf,

  1. Generate the RooPdf’s using the RooClassFactory. This generates two files, MyRooPdf.h and MyRooPdf.cxx
  2. Then create a Linkdef.h file which is required by ROOT to generate a dictionary for the class
  3. Use the rootcint command to generate the dictionary
  4. Create a shared library using your class and its dictionary

I’ve attached some files which hopefully should have everything you need, I made these a while ago, hopefully they still work with the newer versions of ROOT.
Makefile.txt (724 Bytes)
MyRooPdfDict.cxx (65.1 KB)
MyRooPdfDict.h (6.57 KB)
MyRooPdf.cxx (1.26 KB)
MyRooPdf.h (1.1 KB)
LinkDef.h (59 Bytes)

Thanks David, I am going to try it today.

Hi David,

Your method of creating a shared library worked well until I try to include the class into my code. The program compiles but when I run it it gives this error.

error while loading shared libraries: cannot open shared object file: No such file or directory

I tried making new sym links and even copies of the library files. It’s probably something I am doing work in my main makefile so I will keep trying to debug it. Let me know if you already ran into the same problem and know a fix for it already.


Hi Wing,

I think I had the same problem but didn’t solve it. I suspect it might be an issue to do with where the file is located, maybe it needs to be copied into a default location where the compiler looks for it or having some flag telling the compiler where to look?

The way I used my own user class was to load it into CINT, in pyROOT the command to do that is,

import ROOT

x = MyRooPdf(<arguments go here>)

there should be some equivalent command in the CINT shell. Hope that helps.


Hi David,

I solve the problem by adding my custom library path to the g++ line using this -Wl,-rpath option.

g++ $(OBJ) -o $@ $(FLAGS) $(INCS) $(LIBS) -Wl,-rpath=$(shell pwd)/…/Models/ …/Models/

That worked out fine, but when I add a 2nd PDF for example

g++ $(OBJ) -o $@ $(FLAGS) $(INCS) $(LIBS) -Wl,-rpath=$(shell pwd)/…/Models/ …/Models/ …/Models/

Where the Signal and Background PDF are basically made the same way. I get this error

*** glibc detected *** double free or corruption (fasttop):

I think there’s probably something wrong in the way I am linking multiple libs to my program.