Call mathematica math function from root

Dear all,

Since gsl hypergeometric functionsometimes give domain error when I do the fitting, I would like to call mathematica from root.

The web about call mathematica from root interpreter is old and designed for linux, anyone can provide some guide?


My computer system is mac OSX, and I know from this website about call mathematica from C, it works on my computer. … ica-from-c


It is correct that he instructions on ROOT web site are old. But I think if you follow the instructions you provide from … ica-from-c

are valid also for a C++ program.
You just need to add the link to the ROOT include and libraries if you want to use them together.
If you want to use it from the ROOT interpreter, just load your program as a macro in the interpreter after having loaded first the needed Mathematical library (including MathLink)

Best Regards


Dear Lorenzo,

Thanks for your answer, now I can call mathematica using g++ and with root libraries. The command I use is :

g++ my_code.cxx -o my_code -pthread -std=c++1y -m64 -I/Applications/root_v6.06.00/include -L/Applications/root_v6.06.00/lib -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -lm -ldl -lMathmore -lMinuit -I/Applications/ -L/Applications/ -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -lm -ldl -framework Foundation -lstdc++ -lMLi4 -lMLi3

You can notice that I use -lstdc++ and -std=c++1y .

Now it comes another problem, I would like to use Minuit2, but when I use g++, it gives me error

Undefined symbols for architecture x86_64:
“ROOT::Math::factory::CreateMinimizer(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)”, referenced from:
NumericalMinimization(char const*, char const*, int) in ccdYv03S.o

The code I attached,

The command I use is :

g++ NumericalMinimization.cxx -o NumericalMinimization -pthread -std=c++1y -m64 -I/./ -I/Applications/root_v6.06.00/include -L/Applications/root_v6.06.00/lib -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -lm -ldl -lstdc++ -w
NumericalMinimization.cxx (2.84 KB)


I have no problem building your program. Maybe there is a problem finding the ROOT libraries. You should check if you can find correctly the ROOT libraries and you have them installed. You can try with a simpler ROOT program.


Try: `root-config --cxx --cflags` -o NumericalMinimization NumericalMinimization.cxx `root-config --libs`
Also, try:
root-config --features
and see if you have “minuit2” among available features, or try:
root-config --has-minuit2
and see if you get “yes”.
If you do not have “minuit2”, you will need to build your ROOT completely from scratch again (adding, for example, “-Dall=ON” to the cmake configuration step).

Dear Lorenzo,

I may have not expressed clearly, because I use -std=c++1y which is different from “__cxx11” in the error message. I am using MAC OSX, maybe it using c++1y, not cxx11.

And When I use:

clang++ NumericalMinimization.cxx -o NumericalMinimization -pthread -std=c++1y -m64 -I/./ -I/Applications/root_v6.06.00/include -L/Applications/root_v6.06.00/lib -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -lm -ldl -lstdc++ -w

I can get the code running without any problem.

But the calling mathematica can only use g++ not clang++