Calling Julia from Java: Image Not Found


Hello, I asked this on StackOverflow, but this is a better place :slight_smile:

I am calling Julia from Java via JNI.

I have successfully compiled and linked my Julia into a dylib using instructions here:

julia ~/dev/PackageCompiler.jl/juliac.jl -vas f.jl`

I link with a thin layer of C++ to implement the JNI interface. I got the flags from

julia/share/julia/julia-config.jl --allflags


JULIA_LINK_LIBS = -Wl,-rpath,’/Applications/’ -Wl,-rpath,’/Applications/
ontents/Resources/julia/lib/julia’ -ljulia

libTest.jnilib: Test.o builddir/f.dylib
gcc $JAVA_LINK_FLAGS $JULIA_LINK_FLAGS -o libTest.jnilib Test.o builddir/f.dylib JULIA_LINK_LIBS

Test.o: Test.cpp

Everything compiles and links with no complaint, but when I try to call it from Java I get this

Exception in thread “main” java.lang.UnsatisfiedLinkError:
dlopen(/Users/xxx/dev/ie/julia/libTest.jnilib, 1): Library not
loaded: @rpath/f.dylib
Referenced from: /Users/xxx/dev/ie/julia/libTest.jnilib
Reason: image not found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(
at java.lang.ClassLoader.loadLibrary(
at java.lang.Runtime.loadLibrary0(
at java.lang.System.loadLibrary(
at Test.(

I can’t find anything in the docs. I thought PackageCompiler and julia-config would take care of including everything I need. What am I missing?

Thanks Peter


Is f.dylib in the same directory as libTest.jnilib ? Is that your current working directory?


No f.dylib is in builddir and libTest.jnilib is in my current dir. Should I cause them to be in the same place?


Well, the error message suggests that they should be in the same place: @rpath/f.dylib


That didn’t fix it. Can you explain @rpath? How is it set?

Also, am I correct in thinking that my libTest.jnilib is finding f.dylib like any other dylib. But on loading Julia is trying to load an ‘image’ which it is not finding? That image is inside f.dylib