Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYLD environment variable woes on OS X Sierra when running Ant: Library not loaded libANML_g.dylib #181

Open
theronic opened this issue Mar 3, 2018 · 5 comments

Comments

@theronic
Copy link

theronic commented Mar 3, 2018

Ant throws "library not loaded" on OSX Sierra when attempting to build an example from a distribution download pertaining to libANML_g.dylib even though dynamic link environment variables are set.

Solutions on this thread don't work for me. ant seems to look for libANML_g.dylib at /private/tmp/bitteniZMy4G/build_EUROPA_Release_6281/build/lib/libANML_g.dylib when it is located at ../../lib/libANML_g.dylib and DYLD_LIBRARY_PATH is correctly set as well as DYLD_BIND_AT_LAUNCH=YES.

Here is the build output:

~/Projects/europa-2.6-mac64/examples/Light  ant                                                                                                                                                                     ✔  5769  19:09:14
Buildfile: /Users/petrus/Projects/europa-2.6-mac64/examples/Light/build.xml

init:
    [mkdir] Created dir: /Users/petrus/Projects/europa-2.6-mac64/examples/Light/build/classes

compile:
    [javac] Compiling 2 source files to /Users/petrus/Projects/europa-2.6-mac64/examples/Light/build/classes
    [javac] Compiling 1 source file to /Users/petrus/Projects/europa-2.6-mac64/examples/Light/build/classes

run:
     [echo] Running Light project
     [java] Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/petrus/Projects/europa-2.6-mac64/lib/libSystem_g.dylib: dlopen(/Users/petrus/Projects/europa-2.6-mac64/lib/libSystem_g.dylib, 1): Library not loaded: /private/tmp/bitteniZMy4G/build_EUROPA_Release_6281/build/lib/libANML_g.dylib
     [java]   Referenced from: /Users/petrus/Projects/europa-2.6-mac64/lib/libSystem_g.dylib
     [java]   Reason: image not found
     [java] 	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
     [java] 	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
     [java] 	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
     [java] 	at java.lang.Runtime.load0(Runtime.java:809)
     [java] 	at java.lang.System.load(System.java:1086)
     [java] 	at psengine.util.LibraryLoader.loadLibrary(Unknown Source)
     [java] 	at psengine.PSUtil.loadLibraries(Unknown Source)
     [java] 	at Light.Main.main(Main.java:16)

BUILD FAILED
/Users/petrus/Projects/europa-2.6-mac64/examples/Light/build.xml:69: Java returned: 1

Total time: 1 second

Platform: Mac OSX Sierra

Prerequisites installed:

  • brew install ant
  • brew install libantlr3c

Environment Vars:

$ export
...
/Users/petrus/Projects/europa-2.6-mac64
LD_LIBRARY_PATH=:/Users/petrus/Projects/europa-2.6-mac64/lib:/Users/petrus/Projects/europa-2.6-mac64/lib
DYLD_BIND_AT_LAUNCH=YES
...
@theronic
Copy link
Author

theronic commented Mar 4, 2018

When I try to build Europa from source by calling ant release-dist, I get "Env variable DYLD_BIND_AT_LAUNCH=YES must be set to build shared libraries" despite export showing that DYLD_BIND_AT_LAUNCH=YES:

ant release-dist                                                                                                                                                        ✔  5963  01:09:53
Buildfile: /Users/petrus/Projects/europa/build.xml

findPlatform:
     [echo] os.name='Mac OS X' os.arch='x86_64'
     [echo] Running build for : family=unix os=mac 64bit=true

init:

init-unix:

release-dist:

findPlatform:
     [echo] os.name='Mac OS X' os.arch='x86_64'
     [echo] Running build for : family=unix os=mac 64bit=true

init:

init-unix:

build-cpp:

build-cpp-unix:
     [echo] jam   -s64BIT=1 -sLOGGER_TYPE= -sVARIANTS=DEV -sLIBRARIES=SHARED -sPLATFORM_FLAGS="" -sLINKLIBS="" -j1 build
     [exec] Fatal build error:
     [exec] Env variable DYLD_BIND_AT_LAUNCH=YES must be set to build shared libraries.
     [exec]

Something weird with environment variables. Could this be related to SIP on OS X Sierra?

@theronic theronic changed the title ~/europa-2.6-mac64/examples/Light/ant throws "Library not loaded /private/tmp/bitteniZMy4G/build_EUROPA_Release_6281/build/lib/libANML_g.dylib" DYLD environment variable woes on OS X Sierra when running Ant: Library not loaded libANML_g.dylib Mar 4, 2018
@theronic
Copy link
Author

theronic commented Mar 4, 2018

Workaround

Copy the .dylib files in lib folder to /usr/local/lib. Not ideal, obviously.

@theronic
Copy link
Author

theronic commented Mar 4, 2018

Turns out DYLD_LIBRARY_PATH is silently ignored on OS X Sierra due to System Integrity Protection (SIP), which can be turned off by booting into recovery mode by holding Cmd+R while booting. Open Terminal via Utilities and enter:

csrutil disable

Restart again. To re-enable repeat with, csrutil enable

@mcgannc
Copy link
Contributor

mcgannc commented May 26, 2019

Any thoughts on resolving this issue folks?

@miatauro-NASA
Copy link
Contributor

I've looked into this a couple of times, and I haven't come up with a "good" resolution using the ant/jam/make build. It seems like you can:

  1. Disable SIP as @theronic suggests.
  2. Set DYLD_LIBRARY_PATH in main via setenv()
  3. Link statically
  4. Use otool to fix up the paths

Building using CMake seems not to have this problem for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants