Compile outside of ROOT using RooFit classes

Hi All,

I’m trying to compile some code outside of ROOT but encounter problems when I include a RooFit class in some simple test code (here the RooRealVar class).

My test code is:

#include

using namespace std;
using namespace RooFit;

int main(){

RooRealVar t(“t”, “t”, 0., 1.,"");

return 0;
}

I try to compile the code with:

gcc root-config --cflags --libs file.cxx -o exe_file_name

and I get this error:

/tmp/ccww1741.o(.text+0x14b): In function main': : undefined reference toRooRealVar::RooRealVar(char const*, char const*, double, double, char const*)’
/tmp/ccww1741.o(.text+0x183): In function main': : undefined reference toRooRealVar::~RooRealVar()’
/tmp/ccww1741.o(.text+0x1ad): In function main': : undefined reference toRooRealVar::~RooRealVar()'
collect2: ld returned 1 exit status

The code’s fine without the RooRealVar t(“t”, “t”, 0., 1.,""); line and RooRealVar.h is in the root/include dir.

Can anyone tell me where I’m going wrong?

Thanks in advance,

Paul.

1 Like

Hello, Paul.

I’m not sure, but I think, you should specify RooFit’s library manually in a g++ command line.

For example, I can compile and link your sample:

g++ root-config --cflags --libs -L $ROOTSYS/lib -lRooFit -lHtml -lMinuit c.cpp

c.cpp:

#include <RooRealVar> 

using namespace std; 
using namespace RooFit; 

int main(){ 

RooRealVar t("t", "t", 0., 1.,""); 

return 0; 
} 

PS. In include directive must be RooRealVar.h - it’s the problem with formatting.

2 Likes

Yes - that compiles for me too, thanks for the speedy reply.

Paul.

Hi everyone,

I am a root newbie and have a similar problem when trying to compile programs containing roofit objects. But the -lRooFit flag does not solve it. If I compile the c.cpp example file using the command given in the precedent post (with “RooRealvar.h” instead of " included, as advised), I get the following error message :

Undefined symbols: "RooRealVar::RooRealVar(char const*, char const*, double, double, char const*)", referenced from: _main in ccKjomfH.o "RooRealVar::~RooRealVar()", referenced from: _main in ccKjomfH.o ld: symbol(s) not found collect2: ld returned 1 exit status

I got the same message on three different machines (mac 32 with OSX 10.5 and 64 bits with OSX 10.6) with three different Root releases, two of them downloaded pre-compiled with built-in RooFit and the last one with separated compiled RooFit, so I assume the installation is not in question. Do you see what I am doing wrong ?

Hi,

Add -lRooFitCore

Cheers, Axel.

1 Like

Hi Axel,

thanks for answering so quickly, it works and you saved our day.

Cheers.

I need to say a massive thank you for this topic (even though it is old, so apologies for necro-ing it).

I have just got a new MacBook Pro and was configuring ROOT on it and I thought the best way to check was to compile and run some standalone code I had written (using RooFit) to run a brief analysis.

Upon including all the libraries possible, I was getting an issue (which I will put here incase others get the same problem, because this took a lot of googling to find).

Undefined symbols for architecture x86_64: "RooRealVar::RooRealVar(char const*, char const*, double, char const*)", referenced from: _main in analyser.o "RooCmdArg::RooCmdArg()", referenced from: _main in analyser.o "RooFit::Cut(char const*)", referenced from: _main in analyser.o "RooFit::Import(TTree&)", referenced from: _main in analyser.o "RooArgSet::RooArgSet(RooAbsArg const&, RooAbsArg const&, RooAbsArg const&, RooAbsArg const&, char const*)", referenced from: _main in analyser.o "RooDataSet::RooDataSet(char const*, char const*, RooArgSet const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&)", referenced from: _main in analyser.o "RooArgSet::~RooArgSet()", referenced from: _main in analyser.o "RooCmdArg::~RooCmdArg()", referenced from: _main in analyser.o "RooAbsData::numEntries() const", referenced from: _main in analyser.o "RooDataSet::~RooDataSet()", referenced from: _main in analyser.o "RooArgSet::RooArgSet(RooAbsArg const&, char const*)", referenced from: _main in analyser.o "RooRealVar::~RooRealVar()", referenced from: _main in analyser.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status make: *** [analyser.exe] Error 1

Anyway, it turns out that when this code was compiled in Linux, I only needed to include the -lRooFit option, but apparently on Macs, it requires the -lRooFitCore option.
If anyone with more knowledge could shed some light as to what the difference is, I would be very grateful, but as it is, the advise above has resolved my compilation problem.

Hi,

Which version of ROOT were you using (there have been recent change in the linking requirement and setup within the ROOT libraries) …

Cheers,
Philippe.

Sorry for the delayed reply, I didn’t anticipate any questions.

The version of ROOT I am using is 5.32.00. It was pointed out by a member in my office that it might just have been a case that on the Linux setup (which was on our department’s server) there might have been an explicit link to -lRooFitCore inside the root-config libraries somewhere that I wasn’t aware of.