tags:

views:

220

answers:

1

Has anybody successfully ran any Java code using VTK 5.4.2 under OS X?

I've installed VTK 5.4.2 from source, configured for Java and shared libraries. The vtk.jar file is generated as expected, and the Java program compiles correctly. However, when executing, as soon as the wrapper classes call the underlying *.dylib libraries, it appears that only the first library loads, and its dependencies are not found even if they are in the same directory as the first library loaded.

When running using Netbeans, the error I am getting is:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/lib/java/libvtkFilteringJava.dylib: Library not loaded: libvtkCommonJava.5.4.dylib
Referenced from: /usr/lib/java/libvtkFilteringJava.dylib Reason: image not found at java.lang.ClassLoader$NativeLibrary.load(Native Method)

Any ideas?

Thanks- Carlos

+1  A: 

If you add a System.outprintln for System.setProperty("java.library.path"); does it include the directory where ibvtkCommonJava.5.4.dylib?

Also are you running a mix of 32/64 bit on the machine?... and if so is the library compiled for the same as the VM you are using (64-bit VM + 64-bit library or 32-bit VM and 32-bit library).

This talks about the library path: http://www.java-tips.org/other-api-tips/jni/simple-example-of-using-the-java-native-interface.html

TofuBeer
Since I was not sure how to change the java.library.path (setting the property does not do the trick, how does one do that?), I've printed out the path and copied all the VTK shared libs to a directory in the path. So the I assume that the runtime can find them.On the other question, I've built VTK using cmake, and am not familiar with it - looking at the configuration options, I do not see a "-m64" flag, so I assume it is 32 bits. Java reports: Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode), so it is 64bit, apparently.Maybe I should try to rebuild adding the "-m64"...
cjcela
-Djava.library.path will certainly work.
bmargulies
The system properties are generally (always?) read only... I have update my answer.
TofuBeer
Thank you bmargulies, TofuBear - that helped setting the path, and understanding how to link Java with C libraries. Still, it does not work correctly, and I keep getting the same error. The 32 vs 64 bit compile does not helps either, the error message is the same.
cjcela
I might try it on my mac in a while (tomorrow)... if I do I'll update it here with how it goes.
TofuBeer