# Segmentation fault when compiling with gcc

**URL:** <https://root-forum.cern.ch/t/segmentation-fault-when-compiling-with-gcc/32945>\
**Category:** Newbie\
**Created:** [February 27, 2019, 5:27pm UTC](https://root-forum.cern.ch/t/segmentation-fault-when-compiling-with-gcc/32945 "2019-02-27T17:27:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RFH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b487fb/32.png) [@RFH](https://root-forum.cern.ch/u/RFH)\
**Post date:** [February 27, 2019, 5:27pm UTC](https://root-forum.cern.ch/t/segmentation-fault-when-compiling-with-gcc/32945/1 "2019-02-27T17:27:28Z")

</div>

Hello,

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/libCore.so #3 0x00007f54c33e503c in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib/x86\_64-linux-gnu/libCore.so #4 #5 0x00007f54c2f70d6e in TMinuit::mnpars(TString&, int&) () from /usr/lib/x86\_64-linux-gnu/libMinuit.so #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 [http://root.cern.ch/bugs](http://root.cern.ch/bugs). 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/libMinuit.so #6 0x0000000000401805 in main ()

I would really appreciate your help.

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [March 1, 2019, 8:50am UTC](https://root-forum.cern.ch/t/segmentation-fault-when-compiling-with-gcc/32945/2 "2019-03-01T08:50:06Z")

</div>

Hi,

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

```auto
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).
