1

This question already has an answer here:

Here is a brief, self-explanatory bash session on Linux:

$ env | grep LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH=foo
$ env | grep LD_LIBRARY_PATH
LD_LIBRARY_PATH=foo
$ echo $LD_LIBRARY_PATH 
foo

Here is the same session on a Mac:

$ env | grep LD_LIBRARY_PATH
$ export LD_LIBRARY_PATH=foo
$ env | grep LD_LIBRARY_PATH
$ echo $LD_LIBRARY_PATH
foo

Notice that, oddly, env does not include LD_LIBRARY_PATH, even though it has been exported, and echo finds it. But it's not just an env thing. Other programs cannot find the environment variable. Here is a JVM (via the Scala REPL), after setting export LD_LIBRARY_PATH=foo:

scala> System.getenv("LD_LIBRARY_PATH")
res0: String = null

scala> System.getenv("SHELL")
res1: String = /bin/bash

On Linux, System.getenv("LD_LIBRARY_PATH") yields the expected foo.

I'm trying to execute an external process from Scala that needs to inherit LD_LIBRARY_PATH from the parent shell. But if the JVM can't see the parent shell's LD_LIBRARY_PATH, and doesn't inherit automatically, it's hard to get right.

On Linux everything works as expected.

Thank you for your help!

marked as duplicate by nohillside Apr 2 '17 at 10:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    If you are using LD_LIBRARY_PATH on MacOS you probably have got something wrong. If on Sierra SIP stops you setting it. apple.stackexchange.com/questions/212945/… macOS is not the same as Linux. So you need to read up on macOS shared librarioes and bundles. – Mark Apr 2 '17 at 9:30
  • @mark Please post this as an answer :-) – nohillside Apr 2 '17 at 9:58
  • 1
    @patrix - in that case isn't this a dup of the answer I linked to? apple.stackexchange.com/questions/212945/… I was wondering if there was a quick solution or do we have to look at the whole packaging oif the app? – Mark Apr 2 '17 at 10:04
  • @SteveWaldman - You need to provide details of the app you are executing - to see if it can be packaged in a mac way - or could you make it a library and call via JNI – Mark Apr 2 '17 at 10:07
  • @SteveWaldman If you are looking for ways to solve the problem of running an external process from Scala, please ask a new question about this specifically. – nohillside Apr 2 '17 at 10:08

Browse other questions tagged .