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/thisroot.sh’
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 export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH export DYLD_LIBRARY_PATH=$ROOTSYS/lib:$DYLD_LIBRARY_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:
./your-program-name.o
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
http://stackoverflow.com/questions/6309773/link-error-on-mac-osx-10-6-7
P.S. You might need a list of g++ compiler flags:
https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Option-Summary.html#Option%20Summary