Segmentation fault when compiling with gcc


I am trying to run a code with g++ including root libraries. In particular I want to make use of TMinuit. When I compile the code using,

g++ -o Output Input.cpp root-config --cflags root-c onfig --cflags --glibs root-config --ldflags --glibs -lMinuit SomeLibrary.o

there is no problem at all, but when I run the code it gives me a segmentation violation.
The problem seems to be in a line of the code that uses a TMinuit routine:

gMinuit->mnparm(0, "sint2", vstart[0], step[0], 0.0,1.0,ierflg);

Here is the result when I run it

Segmentation fault (core dumped)

There was a crash.
This is the entire stack trace of all threads:

#0 0x00007f54c238c07a in __GI___waitpid (pid=5538, stat_loc=stat_loc
entry=0x7ffef22a2f80, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:29
#1 0x00007f54c2304fbb in do_system (line=) at …/sysdeps/posix/system.c:148
#2 0x00007f54c33e2dd4 in TUnixSystem::StackTrace() () from /usr/lib/x86_64-linux-gnu/
#3 0x00007f54c33e503c in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib/x86_64-linux-gnu/
#5 0x00007f54c2f70d6e in TMinuit::mnpars(TString&, int&) () from /usr/lib/x86_64-linux-gnu/
#6 0x0000000000401805 in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x00007f54c2f70d6e in TMinuit::mnpars(TString&, int&) () from /usr/lib/x86_64-linux-gnu/
#6 0x0000000000401805 in main ()

I would really appreciate your help.


you could make the compilation a bit cleaner if you used something like

g++ -o Output Input.cpp $(root-config --cflags --glibs --ldflags) -lMinuit SomeLibrary.o

Further, are you using Minuit2? In that case you should link against -lMinuit2. Also try using
-Wl,--no-undefined when you link, because it will error out when you have undefined symbols (because you forgot a library when linking).