# G++ compiler strange behavior

**URL:** <https://root-forum.cern.ch/t/g-compiler-strange-behavior/36737>\
**Category:** Newbie\
**Created:** [November 8, 2019, 11:37am UTC](https://root-forum.cern.ch/t/g-compiler-strange-behavior/36737 "2019-11-08T11:37:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicola\_Rizzi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nicola_rizzi/32/18416_2.png) [@Nicola\_Rizzi](https://root-forum.cern.ch/u/Nicola_Rizzi)\
**Post date:** [November 8, 2019, 11:37am UTC](https://root-forum.cern.ch/t/g-compiler-strange-behavior/36737/1 "2019-11-08T11:37:33Z")

</div>

Hi ROOTers,

I am having some problems (again) with the g++ compiler. I made a minimal working example for you [example.cpp](https://root-forum.cern.ch/uploads/short-url/9gM8NvMHogYc5yUuUAvzrVXrm1D.cpp) (416 Bytes) which uses a self-written class [Source.h](https://root-forum.cern.ch/uploads/short-url/ifn5bslJBwi9RUVcWcrOBoHEJDe.h) (870 Bytes) [Source.cpp](https://root-forum.cern.ch/uploads/short-url/zHBW7TgHo1nxLDq8VF8xfCIUfGK.cpp) (2.7 KB)

I try to compile all of them with the following script

```auto
#! /bin/bash
g++ -o example example.cpp `root-config --cflags --libs` source/Source.cpp 
./example

```

But the compiler ( g++ 5.4.0 ) gives me the following error:

```auto
/tmp/ccPsRX1N.o: In function `gauss(double)':
Source.cpp:(.text+0xdd): undefined reference to `TMath::Gaus(double, double, double, bool)'
collect2: error: ld returned 1 exit status

```

which is quite strange since I can compile much more complicated macros like [macro.cpp](https://root-forum.cern.ch/uploads/short-url/AwxTYu7W7NMg1qpKUegqxgU0nCv.cpp) (9.4 KB) using, among the others, the same Source class. In the last case I run

```auto
#! /bin/bash
g++ -o accident macro.cpp `root-config --cflags --libs` source/Source.cpp source/Sobol.cpp source/Utility.cpp source/Transport.cpp source/OuterSource.cpp source/Dispersion.cpp source/Dose.cpp 
./accident

```

and is completely fine. I also tried to run example.cpp using the same script for macro.cpp, but changing just the name and the compiler returns me many more errors of the same type: `undefined reference to TAxis, TVector` etc. in all the other self-written linked classes.

What is going on? I can’t figure it out.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 8, 2019, 11:44am UTC](https://root-forum.cern.ch/t/g-compiler-strange-behavior/36737/2 "2019-11-08T11:44:17Z")

</div>

> [@Problem with library MathCore linker](https://root-forum.cern.ch/t/problem-with-library-mathcore-linker/36631/2):
>
> Try: `root-config --cxx --cflags` -o accident macro.cpp source/Source.cpp source/Utility.cpp source/Transport.cpp source/Output.cpp source/OuterSource.cpp source/Dispersion.cpp source/Dose.cpp `root-config --libs`

> [@Problem with gcc flag/file order when compiling against ROOT libraries](https://root-forum.cern.ch/t/problem-with-gcc-flag-file-order-when-compiling-against-root-libraries/36684/2):
>
> Search for “--as-needed” in [man ld -\> Command Line Options](https://sourceware.org/binutils/docs/ld/Options.html)

---

<div class="post-metadata">

**Author:** ![Nicola\_Rizzi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/nicola_rizzi/32/18416_2.png) [@Nicola\_Rizzi](https://root-forum.cern.ch/u/Nicola_Rizzi)\
**Post date:** [November 8, 2019, 12:12pm UTC](https://root-forum.cern.ch/t/g-compiler-strange-behavior/36737/3 "2019-11-08T12:12:58Z")

</div>

I’m sorry I didn’t know was the same kind of problem. I will do my research to understand this issue once for all.

Thank you
