Compile CERN ROOT program with RooFit in Eclipse

CERN ROOT and Eclipse

Hi guys! I have succeeded compiling my c++ program that utilizes CERN ROOT framework with RooFit in Eclipse. It was a little pain in the ass so I want to share my experience with you. I’m using MacOS 10.10 and Eclipse Luna 4.4.2.

At first after installing ROOT go to your ROOT installation directory and run ‘sh /bin/’

Make sure your environment variables are set. In MacOS they are declared in ~/.bash_profile file. For example, I have:

export ROOTSYS=/Users/petrstepanov/root-6.04.08
export PATH=$ROOTSYS/bin:$PATH

after editing your ‘.bash_profile’ run from terminal ‘source .bash_profile’

CERN Root requires the main function to have the same name as your filename. Now we want to make a standalone program and compiling externally. Doublecheck you have renamed it to main(){} function in your program.

Next, try compiling your RooFit code from console. Add following libraries -lRooFit -lRooFitCore flags (maybe some others too like -lMinuit, -lFumili). Go to program parent folder in terminal and try compile:

g++ `root-config --cflags --libs` -L $ROOTSYS/lib -lRooFit -lRooFitCore -lHtml -lMinuit -lFumili your-program-name.cpp -o your-program-name.o

Then Launch:


If compilation completes successfully it means you can repeat it from Eclipse. Every time you compile in eclipse go to “Console” tab and see the discrepancies of your g++ parameters with the ones that worked for you when you compiled in console. Try following steps:

1. Go to Project -> Properties -> C/C++ Build -> Environment. You should have ROOTSYS, LD_LIBRARY_PATH and DYLD_LIBRARY_PATH set there.

2. Go to Project -> Properties -> C/C++ Build -> Settings -> MacOS X C++ Linker -> Miscellaneous. On the right notice Miscellaneous text field. Paste there identical flags/parameters that worked for you when you compiled from console. I have all other settings under “MacOS X C++ Linker” default/empty.

3. Go to Project -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous. Paste same string there. Since this string has all necessary flags for the compiler I cleared default eclipse settings under “GCC C++ Compiler”. E.G. no include path, no language standart, none optimization.

That’s pretty much it. Below please see the some Eclipse errors that showed up in the console. I briefly state the solutions there

  • Eclipse Output: atomic is not implemented
    Solution you have to use C++11 compiler. This is achieved by adding following parameters -stdlib=libc++ -std=c++11 to the compiler directives.
  • Eclipse Output: symbol(s) not found for architecture x86_64
    Solution: you probably forgot to include one of the libraries (g++ parameter). Doublecheck following flags: -L/path-to-root-libraries/ – make sure path is correct. Also try including include more libraries. The ones that I was missing were -lRooFit -lRooFitCore -lFumili. After adding these flags problem gone.
  • Eclipse Output: unknown type name ‘…’ (in my case – ‘RooAddPdf’ and ‘RooGausian’)
    Solution: cyclic dependency in roofit #include “…” files. Remove all include lines in your code and start adding them as-demanded by compiler again.
  • Eclipse Output: can’t link with a main executable file for architecture x86_64
    Solution: add “-c” to compiler flags – eclipse will not try to link your source file

P.S. You might need a list of g++ compiler flags:

Setting up CERN ROOT framework with Eclipse

Whatsup guys! I have experienced some troubles setting up ROOT framework with Eclipse on MacOS. It took me hours to find the right articles. Here is the way that worked for me.

First I have installed ROOT with homebrew. You can find the instructions in this article:

Now we want to setup ROOT and Eclipse.

Download and install Eclipse with CDT (you can have 2 eclipses at a time one for java and other for c :-)
Next follow this link:

If you need the ROOT homebrew installation directory just type in terminal

“brew info root”

Finally some compiler optimizations can be found in this article:

Good luck!

RooChi2Var how-to

About chi^2 quantiles

How to evaluate critical values of chi^2



Get number of free parameters