# Compillation of macros and shared libraries

**URL:** <https://root-forum.cern.ch/t/compillation-of-macros-and-shared-libraries/56248>\
**Category:** Cling\
**Created:** [September 1, 2023, 2:36pm UTC](https://root-forum.cern.ch/t/compillation-of-macros-and-shared-libraries/56248 "2023-09-01T14:36:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gonzalo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@Gonzalo](https://root-forum.cern.ch/u/Gonzalo)\
**Post date:** [September 1, 2023, 2:36pm UTC](https://root-forum.cern.ch/t/compillation-of-macros-and-shared-libraries/56248/1 "2023-09-01T14:36:17Z")

</div>

This is a dummy version of the problem (using ROOT version 6.24/09):  
I would like to create a shared library (dummy.cc):

```auto
#ifdef SUM0
    int sum0(int x){return x+0;}
#endif

int sum1(int x){return x+1;}

```

This can be done (see manual/root\_macros\_and\_shared\_libraries/) through a ROOT shell using the Load directive

```auto
root [0] .L dummy.cc++

```

Of course this only compiles the **sum1** function as SUM0 is not defined.

Is it possible to activate the SUM0 block?  
In fact it is but I am not sure if this is the expected behaviour…

```auto
root [0] gSystem->AddIncludePath("-DSUM0")
root [1] .L dummy.cc++

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 1, 2023, 2:49pm UTC](https://root-forum.cern.ch/t/compillation-of-macros-and-shared-libraries/56248/2 "2023-09-01T14:49:31Z")

</div>

Welcome to the ROOT forum.

If the method you are using works why not using it ? May be have a look at [CompileMacro](https://root.cern/doc/master/classTSystem.html#ac557d8f24d067a9b89d2b8fb261d7e18), it seems that’s what you are looking for.

---

<div class="post-metadata">

**Author:** ![Gonzalo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@Gonzalo](https://root-forum.cern.ch/u/Gonzalo)\
**Post date:** [September 1, 2023, 3:36pm UTC](https://root-forum.cern.ch/t/compillation-of-macros-and-shared-libraries/56248/3 "2023-09-01T15:36:21Z")

</div>

Thanks for the response.  
Sure it works, but I would have expected **AddIncludePath** to be used to add only include paths, thus adding -I flag.  
From the reference you are pointing out, I have also tryed  
`gSystem->SetMakeExe("g++ -Wall -fPIC $IncludePath $SourceFiles -o $ExeName $LinkedLibs -DSUM0")`  
but the -DSUM0 flags is not being obeyed.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [September 5, 2023, 8:17am UTC](https://root-forum.cern.ch/t/compillation-of-macros-and-shared-libraries/56248/4 "2023-09-05T08:17:15Z")

</div>

Hi,

This is really for historical reasons - people used `AddIncludePath()` to pass extra flags and now we have to support it 🙂

You want to use `TSystem::SetMakeSharedLib()` not `SetMakeExe()`.

Cheers, Axel

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [September 19, 2023, 8:17am UTC](https://root-forum.cern.ch/t/compillation-of-macros-and-shared-libraries/56248/5 "2023-09-19T08:17:53Z")

</div>

Closed on September 19, 2023, 8:17am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
