# ROOT Dynamic Library Path

**URL:** <https://root-forum.cern.ch/t/root-dynamic-library-path/24305>\
**Category:** ROOT\
**Created:** [April 3, 2017, 8:39pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305 "2017-04-03T20:39:23Z")\
**Posts on this page:** 15\
**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 3, 2017, 8:39pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/1 "2017-04-03T20:39:23Z")

</div>

Hi,

Previously I was able to create libraries to extend the functionality of ROOT. By adding their path to `(DY)LD_LIBRARY_PATH` one could simply type `gSystem->Load("libRary.dylib")`. This unfortunately is no longer possible on Mac OSX 10.12 as the use of `DYLD_LIBRARY_PATH` has been depreciated. I could simply put the whole path to the library, but asking other users to do this becomes unreasonable. I see a message when one evokes the `gSystem::Load` method without the proper path that there may be a internal search path:

```auto
Error in <TRint::ProcessLine>: macro libRary.dylib not found in path .:/opt/root/root-6.08.06/macros:

```

Is there anyway to extend this path? Possibly the `LIBRARY_PATH` used by gcc? My preference here is that the user would setup there environment in some way and upon evoking root the library will be available for use without any further input.

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 4, 2017, 6:26am UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/2 "2017-04-04T06:26:19Z")

</div>

Hi,

That’s Apple’s “System Integrity Protection”. AFAIK, LD\_LIBRARY\_PATH is only ignored for binaries in /usr etc: [https://support.apple.com/en-us/HT204899](https://support.apple.com/en-us/HT204899). If your ROOT is in /opt I would have expected it to work.

Either way, installing it into /home/your-user/root/ should also fix this.

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 4, 2017, 2:46pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/3 "2017-04-04T14:46:25Z")

</div>

Hi,

It is worse then that. The export command ignores all `DYLD_` environment variables and as I understand it all protected processes continuously purge these variables as well. This makes the variable useless as it is always being unset. [https://developer.apple.com/library/content/documentation/Security/Conceptual/System\_Integrity\_Protection\_Guide/RuntimeProtections/RuntimeProtections.html](https://developer.apple.com/library/content/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html)

---

<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 4, 2017, 3:15pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/4 "2017-04-04T15:15:17Z")

</div>

Yeah but the important part is _protected_ processes. Putting it into `$HOME` should leave ROOT unprotected. Which is a good thing 😉 Just try!

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 4, 2017, 3:19pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/5 "2017-04-04T15:19:01Z")

</div>

I will give it a try, but I’m not sure I understand. For example, if I use the `thisroot.sh` script to setup the root environment and then I run a simple `ls` it will unset the `DYLD_LIBRARY_PATH` and then I’m back to square one. (This is similar to what I wanted to do: user loads a bash script to setup the environment for additional ROOT libraries and then starts root.)

Also, it is unreasonable for me to ask all the other users of the software to install ROOT into `$HOME`, so it is not a great solution.

---

<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 5, 2017, 6:04am UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/6 "2017-04-05T06:04:24Z")

</div>

Hi,

Calling `ls` doesn’t unset the env var in the current process, but only in sub-processes. E.g. if you use `python`'s `subprocess`, or `make`. So it all depends on the location of ROOT. I see three options:

- sign ROOT (unlikely, involves lots of Apple interaction)
- install ROOT into an unprotected area
- disable SIP.

Out of those, the second looks like the most reasonable.

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 5, 2017, 12:25pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/7 "2017-04-05T12:25:05Z")

</div>

Alright, to me they all sound unreasonable.

- signing ROOT, I haven’t had success with this in the past and asking a user to do it would be too difficult.
- install ROOT into an unprotected area, many users use package managers to install ROOT and I can’t decide where they put it.
- disable SIP, although some users would do this, I’m not sure 100% will and especially for the gains in this project.

Thanks for the help. Looks like I’m stuck at the moment.

To get back to the original question though where are these directories coming from? They surely are not in my `DYLD_LIBRARY_PATH`:

```auto
[0] gSystem->Load("libRary.dylib")
Error in <TRint::ProcessLine>: macro libRary.dylib not found in path .:/opt/root/root-6.08.06/macros:

```

---

<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 5, 2017, 2:17pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/8 "2017-04-05T14:17:44Z")

</div>

Hi,

Right - good question, that should also allow us to solve this.

First of all I’d like to understand why I get a different error message:

```auto
root [6] gSystem->Load("libhpxkjlkjl.kjdlkjfg")
Error in <TMacOSXSystem::FindDynamicLibrary>: libhpxkjlkjl.kjdlkjfg[.so | .dll | .dylib | .sl | .dl | .a] does not exist in ...

```

That’s what I’d expect to see. And I get this in both ROOT 6-08-00-patches and the master. So either we changed something since 6.08.06 that I am not aware of, or your ROOT isn’t the ROOT version I expect it to be.

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 5, 2017, 2:29pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/9 "2017-04-05T14:29:42Z")

</div>

Ahh my bad. I thought `.L library.dylib` and `gSystem->Load("library.dylib")` executed the same code, this is not the case:

```auto
root [0] gSystem->Load("libRary.dylib")
Error in <TMacOSXSystem::FindDynamicLibrary>: libRary.dylib does not exist in /opt/root/root-6.08.06/lib:::.:/opt/root/root-6.08.06/lib::/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:
(int) -1
root [1] .L libRary.dylib
Error in <TRint::ProcessLine>: macro libRary.dylib not found in path .:/opt/root/root-6.08.06/macros:

```

I was replying away from my production machine and just tossed the two outputs into a code block without trying it, should have checked. I was confused as the either of the following work for loading libraries:

```auto
root [2] .L ~/library/install/lib/libRary.dylib
root [3] gSystem->Load("~/library/install/lib/libRary.dylib")
(int) 1

```

---

<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 5, 2017, 2:33pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/10 "2017-04-05T14:33:48Z")

</div>

Okay, good. Do you have a ROOT install in /opt such that we can try things out?

If so, could you run

```auto
LD_LIBRARY_PATH=foo:$LD_LIBRARY_PATH root -l -b
root [0] printf("%s\n", getenv("LD_LIBRARY_PATH"))

```

and send the output?

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 5, 2017, 2:38pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/11 "2017-04-05T14:38:33Z")

</div>

With `LD_LIBRARY_PATH` on Mac OS X 10.12 Sierra

```auto
$ LD_LIBRARY_PATH=foo:$LD_LIBRARY_PATH root -l -b
root [0] printf("%s\n", getenv("LD_LIBRARY_PATH"))
foo:
(int) 5

```

and with `DYLD_LIBRARY_PATH`

```auto
DYLD_LIBRARY_PATH=foo:$DYLD_LIBRARY_PATH root -l -b
root [0] printf("%s\n", getenv("DYLD_LIBRARY_PATH"))
/opt/root/root-6.08.06/lib:foo:
(int) 32

```

---

<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:43pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/12 "2017-04-05T14:43:32Z")

</div>

For completeness:

```auto
$ DYLD_LIBRARY_PATH=~/library/install/lib/ root -l
root [0] printf("%s\n", getenv("DYLD_LIBRARY_PATH"))
/opt/root/root-6.08.06/lib:/Users/user/library/install/lib/
(int) 66
root [1] .L libRary.dylib
Error in <TRint::ProcessLine>: macro libRary.dylib not found in path .:/opt/root/root-6.08.06/macros:
root [2] gSystem->Load("libRary.dylib")
(int) 0
root [3]

```

It seems that the `.L libRary.dylib` command does not follow `DYLD_LIBRARY_PATH`, but will use absolute paths and `gSystem::Load` works for either case.

---

<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 6, 2017, 8:28am UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/13 "2017-04-06T08:28:53Z")

</div>

Or you use `(DY)LD_LIBRARY_PATH` and `gSystem->Load("libRary.dylib")` - that works, too, right? Is that an option? Problem solved?

---

<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 6, 2017, 2:34pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/14 "2017-04-06T14:34:26Z")

</div>

I believe this issue has been resolved. The misunderstanding was two fold:

1. Mac OS X 10.12 does not display the value of `[DY]LD_*` environemnt variables when using `printenv`. Tis leads one to thinking that those environment variables are not set.
2. `.L libRary.dylib` does not follow `[DY]LD_LIBRARY_DIR`, but will load libraries if it finds them. This is confusing as it sometimes works and sometimes doesn’t. The error message provided lists search paths for macros not libraries. The solution here is to use `gSystem::Load` which is often confused as the same command, but will follow the `[DY]LD_LIBRARY_PATH`.

---

<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 20, 2017, 2:40pm UTC](https://root-forum.cern.ch/t/root-dynamic-library-path/24305/15 "2017-04-20T14:40:33Z")

</div>

Closed on April 20, 2017, 2:40pm UTC

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