# Loading namespace in macro

**URL:** <https://root-forum.cern.ch/t/loading-namespace-in-macro/32710>\
**Category:** ROOT\
**Created:** [February 12, 2019, 8:14pm UTC](https://root-forum.cern.ch/t/loading-namespace-in-macro/32710 "2019-02-12T20:14:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwielane](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dwielane/32/12354_2.png) [@dwielane](https://root-forum.cern.ch/u/dwielane)\
**Post date:** [February 12, 2019, 8:14pm UTC](https://root-forum.cern.ch/t/loading-namespace-in-macro/32710/1 "2019-02-12T20:14:44Z")

</div>

Dear ROOTers,  
Is there “nice looking” way to load given namespaces in my macro? Lets say that I have MyLib that contains MyNamespace and MyClass. Now I have to use MyClass before calling namespace e.g.

```auto
MyClass *d = 0x0;
Int_t val = MyNamespace::Something();

```

I tried to call gSystem-\>Load(“MyClass”) but this it doesn’t help

* * *

\_ROOT Version: 6.10/80  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![abeiter](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@abeiter](https://root-forum.cern.ch/u/abeiter)\
**Post date:** [February 12, 2019, 10:19pm UTC](https://root-forum.cern.ch/t/loading-namespace-in-macro/32710/2 "2019-02-12T22:19:34Z")

</div>

You can have some file, MyLib.h:

```auto
namespace MyNamespace {
  Int_t Something() {...}
}
class MyClass {...};

```

And in your macro, you can do

```auto
#include "MyLib.h"
void myMacro() {
  Int_t val = MyNamespace::Something();
}

```

Does this help?

---

<div class="post-metadata">

**Author:** ![dwielane](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dwielane/32/12354_2.png) [@dwielane](https://root-forum.cern.ch/u/dwielane)\
**Post date:** [February 13, 2019, 12:01pm UTC](https://root-forum.cern.ch/t/loading-namespace-in-macro/32710/3 "2019-02-13T12:01:08Z")

</div>

Hi,  
actually is not an option because there is no MyLib.h file, I create “MyLib” from MyNamespace MyClass and few other classes. I tried to include “raw” MyNamespace.h but it gives me error  
"IncrementalExecutor::executeFunction: symbol X unresolved while linking [cling interface function]!. C++filt says that this “X” points to method in my namespace.  
However thanks to you I found better (still not perfect) solution - I can include header with something like:

```auto
MyClass *completelyUselessNullPointer;

```

And it works.

---

<div class="post-metadata">

**Author:** ![abeiter](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/4491bb/32.png) [@abeiter](https://root-forum.cern.ch/u/abeiter)\
**Post date:** [February 13, 2019, 12:26pm UTC](https://root-forum.cern.ch/t/loading-namespace-in-macro/32710/4 "2019-02-13T12:26:09Z")

</div>

Ah, so then perhaps [https://root-forum.cern.ch/t/load-a-standalone-sharedlibrary/28306](https://root-forum.cern.ch/t/load-a-standalone-sharedlibrary/28306) is your best bet. I hope this helps.

---

<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:** [February 13, 2019, 12:32pm UTC](https://root-forum.cern.ch/t/loading-namespace-in-macro/32710/5 "2019-02-13T12:32:00Z")

</div>

> [@Namespace in my own library](https://root-forum.cern.ch/t/namespace-in-my-own-library/32365/8):
>
> We cannot autoload nor autoparse functions. The usual workaround is to declare a class inside the namespace AGeoUtil and create a #pragma link C++ class statement for that. This will be fixed by C++ modules; the upcoming v6.16 will be a preview release for those (i.e. they are coming!) 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:** [February 27, 2019, 12:32pm UTC](https://root-forum.cern.ch/t/loading-namespace-in-macro/32710/6 "2019-02-27T12:32:03Z")

</div>

Closed on February 27, 2019, 12:32pm UTC

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