2
votes

I'm trying to use jpl with swi-prolog on Mac OS High Sierra and I'm having troubles. In fact, at first the libjpl.dylib was not found so I added the path to it to java.library.path via

java -Djava.library.path=/Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin15.6.0/

Now the library is found but I get another error:

java.lang.UnsatisfiedLinkError: /Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin15.6.0/libjpl.dylib: dlopen(/Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin15.6.0/libjpl.dylib, 1): Library not loaded: @executable_path/../swipl/lib/x86_64-darwin15.6.0/libswipl.dylib
  Referenced from: /Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin15.6.0/libjpl.dylib
  Reason: image not found
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    ...

From what I understand, this is caused by this version of swi-prolog being relocatable (and thus having path relative to the executable).

The output of otool -L of the libjpl.dylib give me this output:

/Applications/SWI-Prolog.app/Contents/swipl/lib/x86_64-darwin15.6.0/libjpl.dylib:
    @rpath/libjsig.dylib (compatibility version 1.0.0, current version 1.0.0)
    @rpath/libjvm.dylib (compatibility version 1.0.0, current version 1.0.0)
    @executable_path/../swipl/lib/x86_64-darwin15.6.0/libswipl.dylib (compatibility version 0.0.0, current version 7.6.4)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

So one way of fixing it would be to install a not relocatable version via macport or homebrew.

The thing is, neither the macport nor the homebrew version of swi-prolog contain the libjpl.dylib library :/

Am I missing something here ? What can I do to make this work ?

1

1 Answers

1
votes

On macOS 10.13.6 (High Sierra), I regularly compile the SWI-Prolog 7.x sources using:

$ make distclean && ./build && swipl -g "jpl_config_dylib" -t halt

The jpl_config_dylib/0 finds and fixes the Java paths. You should also be able to call it from the top-level after you start the SWI-Prolog.app application.