# Unloading? a library or loading a library again?

**URL:** <https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330>\
**Category:** ROOT\
**Created:** [April 5, 2017, 2:34pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330 "2017-04-05T14:34:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [April 5, 2017, 2:34pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/1 "2017-04-05T14:34:25Z")

</div>

Hi,

On another [thread](https://root-forum.cern.ch/t/loading-a-library-from-a-script/24306/5) we discussed how to load a custom library when executing a script. A solution was proposed that worked for the first execution of the script, but upon a repeated execution the script failed:

> [@Loading a library from a script](https://root-forum.cern.ch/t/loading-a-library-from-a-script/24306/6):
>
> Also, what do I need to do so that I can recall the same macro multiple times? Currently it crashes with warning of ‘unknown types’ when calling it more than once:
> 
> [0] .x macro.C  
> Success!  
> [1] .x macro.C  
> … error: unknown type name ‘foo’ …
> 
> EDIT: I tried wrapping the library loading in a header guard, but that didn’t resolve the issue.

I was asked to open a new thread to discuss the issue, so here it is.

Thanks

---

<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:** [April 7, 2017, 2:17pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/2 "2017-04-07T14:17:57Z")

</div>

Hi,

Unloading is still not fully supported, to the extent we’re aiming for, in ROOT 6. Your best options is sadly to quit ROOT and start again.

I have added a bug report to track this: [https://sft.its.cern.ch/jira/browse/ROOT-8745](https://sft.its.cern.ch/jira/browse/ROOT-8745)

Cheers, Axel.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [April 7, 2017, 2:36pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/3 "2017-04-07T14:36:14Z")

</div>

Thanks for starting the bug report.

Is there a way to somehow just avoid reloading the library and simply using what was previously loaded? Some sort of if statement wrapped around like the following nonworking example:

```auto
#ifndef LIBRARY_LOADED
#define LIBRARY_LOADED
R__LOAD_LIBRARY(libFoo.dylib)
#endif // LIBRARY_LOADED

```

---

<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:** [April 7, 2017, 2:38pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/4 "2017-04-07T14:38:33Z")

</div>

Hmm - I’m not sure it’s the library loading that’s causing this.

Even if you do

```auto
gSystem->Load("libFoo.dylib");
.x scriptAfterRemovingR__LOAD_LIBRARY.C
.x scriptAfterRemovingR__LOAD_LIBRARY.C

```

it might still fail, and likely the same way…

Axel.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [April 7, 2017, 2:45pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/5 "2017-04-07T14:45:40Z")

</div>

And why is that? There is some underlying mechanics here that I don’t understand.

---

<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:** [April 7, 2017, 2:47pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/6 "2017-04-07T14:47:50Z")

</div>

Because reloading of that script fails. It works for some, fails for some, and we’re going to make lots of progress on it this year (we have a couple of crucial pull requests pending on that already).

Axel

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [April 7, 2017, 2:55pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/7 "2017-04-07T14:55:02Z")

</div>

Alright, Thanks for the info. I’ll hold my breath and see whats coming.

For now I’ve stepped around the problem by having two macros. The first loads the library and the second does the work. I can reload the second ad nauseum without any issues.

```auto
/// Loading script, load this only once.
{
   gSystem->Load("libFoo.dylib");
   gSystem->ProcessLine(".L workMacro.C");
}

```

```auto
// Work macro, can be reloaded with `.L workMacro.c`
void workMacro() {
   //Do some work
}

```

---

<div class="post-metadata">

**Author:** ![musinsky](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/musinsky/32/11106_2.png) [@musinsky](https://root-forum.cern.ch/u/musinsky)\
**Post date:** [April 7, 2017, 4:39pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/8 "2017-04-07T16:39:00Z")

</div>

```auto
 if (!TClassTable::GetDict("TFoo")) {
    gSystem->Load("libFoo.so");
  }

```

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [April 7, 2017, 4:50pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/9 "2017-04-07T16:50:34Z")

</div>

> [@musinsky](#):
>
> if (!TClassTable::GetDict(“TFoo”)) {  
> gSystem-\>Load(“libFoo.so”);  
> }

This doesn’t quite resolve the issue, and brings us back to the previous thread: [Loading a library from a script](https://root-forum.cern.ch/t/loading-a-library-from-a-script/24306)

---

<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:** [April 21, 2017, 4:50pm UTC](https://root-forum.cern.ch/t/unloading-a-library-or-loading-a-library-again/24330/10 "2017-04-21T16:50:56Z")

</div>

Closed on April 21, 2017, 4:50pm UTC

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