1

I need to set LD_LIBRARY_PATH for an application using native DLLs. The reason is that I need to import two native DLLs, one depending on the other. JVM's -Djava.library.path only works for resolving the first library, but it's dependency is resolved using the dynamic loader policy, which is given by LD_LIBRARY_PATH. I use fork in test := true and fork in run := true. I use javaOptions ++= Seq(s"-Djava.library.path=...").

How do I set LD_LIBRARY_PATH? Meta-question: how do I navigate sbt APIs so I can learn how to set LD_LIBRARY_PATH on my own?

  • You can also use `System.loadLibary()` to explicitly load your dependencies. That's probably easier than trying to set `LD_LIBRARy_PATH` or `PATH` (windows), which typically must be set in the environment. – technomage Nov 13 '15 at 14:48
  • I am using System.load(), via a third party jar. As I described above, that only works for the top level dll, not for its dependencies. Specifically, System.load() will find `libz3java.dylib` using `-Djava.library.path` or an absolute path, but will not load `libz3.dylib` it because the dylinker will fail. The only way to make `libz3.dylib` loadable as a dependency is via LD_LIBRARY_PATH. – Cristian Petrescu-Prahova Nov 13 '15 at 19:41
  • Have you tried calling `System.load()` on `libz3.dylib` first? You'll likely need an absolute path, but you'd have to inject that into `LD_LIBRARY_PATH` anyway. BTW, on OSX you may need `DYLD_LIBRARY_PATH` instead of `LD_LIBRARY_PATH`. – technomage Nov 16 '15 at 01:49
  • Yes, I did. It doesn't work. – Cristian Petrescu-Prahova Nov 17 '15 at 02:43
  • Seems like the problem may be [specific to OSX](http://stackoverflow.com/questions/17776507/java-web-start-load-native-dependency-with-another-native-dependency). – technomage Nov 17 '15 at 15:35
  • It is, indeed an OS-specific problem. JVM's System.load() is a leaky abstraction. It exhibits on both Linux and OSX, and the solution is similar. Re-iterate the original questions: How do I set LD_LIBRARY_PATH using sbt? – Cristian Petrescu-Prahova Nov 17 '15 at 18:58

0 Answers0