RooFit issue

Hi,
I’m trying to run this simple C++ macros


#include <iostream>
#include "RooRealVar.h"
#include "TTree.h"
#include "TCanvas.h"
#include "RooDataSet.h"
#include "RooPlot.h"
#include "RooGaussian.h"

using namespace RooFit;


int main(){

    RooRealVar x("x", "x", -10, 10);
    RooRealVar mean("mean", "mean of Gaussian", 0, -10, 10);
    RooRealVar sigma("sigma", "width of Gaussian", 3, -10, 10);
    
    RooGaussian gauss("gauss", "Gaussian PDF", x, mean, sigma);
    
    
    TCanvas * c1 = new TCanvas("c1", "Curva Gaussiana");
    TCanvas * c2 = new TCanvas("c2", "Hist Gaussiana");
    TCanvas * c3 = new TCanvas("c3", "Dati-Gaussiana");
    
    c1-> cd();
    // Plot PDF
    RooPlot * xframe1 = x.frame(Title("Gaussian PDF"));
    gauss.plotOn(xframe1);
    xframe1-> Draw();
    
    //Generate a toy MC sample and Plot PDF
    RooDataSet * data = gauss.generate(x, 10000);
    
    c2-> cd();
    RooPlot * xframe2 = x.frame(Title("MC Gaussian data"));
    data-> plotOn (xframe2);
    xframe2->Draw();
    
    //ML fit of gauss to data
    
    c3-> cd();
    gauss.fitTo(*data);
    mean.Print();
    sigma.Print();
    
    RooPlot * xframe3 = x.frame(Title("ML Fit to a MC Gaussian sample"));
    data->plotOn(xframe3, Name("myHist1"));
    gauss.plotOn(xframe3, Name("myCurve1"));
    gauss.paramOn(xframe3);
    xframe3->Draw();
    
    
    Double_t  chi2_1 = xframe3->chiSquare("myCurve1", "myHist1");
    std::cout<<"chi2 = " << chi2_1 << std::endl;


    return 0;
}

with this makefile


LIBS:=`root-config --libs`
INCS:=`root-config --cflags`

prova: prova.o 
	g++ -o $@ $^ ${LIBS} -lRooFit -lTMVA -lMLP -lTreePlayer -lMinuit 

%.o: %.cpp
	g++ -c $< ${INCS}

but i got the following errors


g++ -c macro.cpp `root-config --cflags`
g++ -o macro macro.o `root-config --libs` -lRooFit -lTMVA -lMLP -lTreePlayer -lMinuit 
Undefined symbols for architecture x86_64:
  "RooRealVar::RooRealVar(char const*, char const*, double, double, char const*)", referenced from:
      _main in macro.o
  "RooRealVar::RooRealVar(char const*, char const*, double, double, double, char const*)", referenced from:
      _main in macro.o
  "RooRealVar::~RooRealVar()", referenced from:
      _main in macro.o
  "RooRealProxy::~RooRealProxy()", referenced from:
      RooGaussian::~RooGaussian() in macro.o
  "RooFit::Name(char const*)", referenced from:
      _main in macro.o
  "RooFit::Title(char const*)", referenced from:
      _main in macro.o
  "RooAbsPdf::~RooAbsPdf()", referenced from:
      RooGaussian::~RooGaussian() in macro.o
  "RooArgSet::RooArgSet(RooAbsArg const&, char const*)", referenced from:
      _main in macro.o
  "RooArgSet::~RooArgSet()", referenced from:
      _main in macro.o
  "RooCmdArg::none()", referenced from:
      _main in macro.o
  "RooCmdArg::~RooCmdArg()", referenced from:
      _main in macro.o
  "RooAbsRealLValue::frame(RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&) const", referenced from:
      _main in macro.o
  "RooPlot::chiSquare(char const*, char const*, int) const", referenced from:
      _main in macro.o
  "RooAbsPdf::generate(RooArgSet const&, double, bool, bool, char const*, bool, bool) const", referenced from:
      _main in macro.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [macro] Error 1

can anyone help me ?
thanks

Try the following makefile: [code]CXX:=root-config --cxx
CXXFLAGS:=root-config --cflags
LIBS:=root-config --libs

macro: macro.o
${CXX} ${CXXFLAGS} -o $@ $^ ${LIBS} -lRooFit -lRooFitCore -lTMVA -lMLP -lTreePlayer -lMinuit

%.o: %.cpp
${CXX} ${CXXFLAGS} -c $<

clean:
rm -f *~ macro.o macro[/code]

I got the same error !


`root-config --cxx` `root-config --cflags` -o macro macro.o `root-config --libs` -lRooFit -lTMVA -lMLP -lTreePlayer -lMinuit
clang: warning: argument unused during compilation: '-pthread'
Undefined symbols for architecture x86_64:
  "RooRealVar::RooRealVar(char const*, char const*, double, double, char const*)", referenced from:
      _main in macro.o
  "RooRealVar::RooRealVar(char const*, char const*, double, double, double, char const*)", referenced from:
      _main in macro.o
  "RooRealVar::~RooRealVar()", referenced from:
      _main in macro.o
  "RooRealProxy::~RooRealProxy()", referenced from:
      RooGaussian::~RooGaussian() in macro.o
  "RooFit::Name(char const*)", referenced from:
      _main in macro.o
  "RooFit::Title(char const*)", referenced from:
      _main in macro.o
  "RooAbsPdf::~RooAbsPdf()", referenced from:
      RooGaussian::~RooGaussian() in macro.o
  "RooArgSet::RooArgSet(RooAbsArg const&, char const*)", referenced from:
      _main in macro.o
  "RooArgSet::~RooArgSet()", referenced from:
      _main in macro.o
  "RooCmdArg::none()", referenced from:
      _main in macro.o
  "RooCmdArg::~RooCmdArg()", referenced from:
      _main in macro.o
  "RooAbsRealLValue::frame(RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&) const", referenced from:
      _main in macro.o
  "RooPlot::chiSquare(char const*, char const*, int) const", referenced from:
      _main in macro.o
  "RooAbsPdf::generate(RooArgSet const&, double, bool, bool, char const*, bool, bool) const", referenced from:
      _main in macro.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [macro] Error 1

First execute “make clean” and then “make”.

HI,
i’ve followed your instructions and now it works.
Thank you so much.
Cheers
Giorgio

Hello,

I’m receiving a very similar error with the attached Makefile on macOS Sierra (10.12.4). I tried to solve the issue with the suggestion above but didn’t work. Could anyone comment on this?

Makefile.txt (1.6 KB)

Best,
Bora

1 Like