[vtkusers] Compiling VTK on OSX with .jnilib extensions

Thiébault Benoît dev at artenum.com
Fri Oct 29 06:46:01 EDT 2010


Hi everyone,

I finally managed to embed VTK in an OSGi bundle. The short story is that I modified the way VTK wrapping is done by:
- changing .dylib extensions to .jnilib (Apple VM does not deal well with dylib files)
- adding @loader_path in the library dependencies (to tell Apple VM to look for the transitive dependencies where all the libraries are, and not we the VM is launched)
- removing the version number of the jnilib file names (to address OSGi way to load native libraries)

The full story of why and how I did it is described in detail in my updated post (it quite long, sorry about that): http://dev.artenum.com/blog/ben/posts/osgi_vtk_and_macosx

Now, my bundle successfully finds the native libraries... but crashes with a "Invalid memory access" error.
Which is going to be the topic of my next mail to the mailing list :-)

Regarding VTK Java wrapping, it would be very nice if Kitware would integrate the modifications I made (jnilib extension, @loader_path and no version number in dynamic library files names).
I am not familiar enough with CMake to integrate those changes BEFORE running CMake configuration and generation, that's why I used Shell scripts to modify the libraries. But if someone would do it directly in CMake configuration, that would be awesome. Not only will it allow people to use OSGi and Eclipse RCP for VTK applications, but it will allow to use the Java properties when launching a Java application using VTK (java -Djava.library.path=path/to/my/libs -jar myApp.jar) which currently does not work on OSX.

Kind regards,

Benoît

Le 27 oct. 2010 à 16:41, Thiébault Benoît a écrit :

> Thank you, it seems to work.
> My compilation has restarted... I will know in around an hour if my jnilib compilation works :-)
> Ben
> 
> Le 27 oct. 2010 à 16:34, Michael Jackson a écrit :
> 
>> If you have applied Apple's latest java update there seems to be a problem with a symlink to the jni.h header. There are a few recent posts (as recent as yesterday) on this list with the solution. Maybe that will help you.
>> 
>> Here is the quote from that email:
>> ----- david.gobbi at gmail.com Said........
>> Ah, reading what you said about symlinks in your email, I realized
>> that if people just copy files between the two directories that I
>> mentioned in my email, they will copy over the symlinks instead of
>> copying to the directory that the symlinks point to.  To be clear,
>> what people should do is copy
>> 
>> /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Headers/*
>> 
>> to
>> 
>> /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Headers/
>> 
>> or just change CMakeCache.txt to use the SDK's include directory.
>> 
>> - David
>> 
>> ___________________________________________________________
>> Mike Jackson                      www.bluequartz.net
>> 
>> 
>> On Oct 27, 2010, at 10:28 AM, Thiébault Benoît wrote:
>> 
>>> Hi everyone,
>>> 
>>> It seems nobody has a solution for this problem... Here is a more detailed explanation of the issues I face in creating an OSGi bundle for VTK under OSX: http://dev.artenum.com/blog/ben/posts/osgi_vtk_and_macosx
>>> 
>>> I am sure that this would be very useful to many users, as it would allow them to develop Eclipse RCP applications using VTK.
>>> 
>>> I tried to do change the dylib extension to jnilib extensions myself, but I barely know CMake and I am sure there is a simpler way (that works...) to do it.
>>> 
>>> What I have done so far is first to identify what files in the build directory are referring to .dylib files. For this, I used the command:
>>> grep -r -H ".dylib" .|awk -F':' '{print $1}'|sort|uniq|grep -v "^Binary"
>>> 
>>> The first file, CMakeCache.txt indicates path to system libraries, so I excluded it from the list.
>>> I then replaced all .dylib occurrences by .jnilib extension. Yeah, I know, that's very brutal... if only it could have worked :-)
>>> The compilation fails at 8%:
>>> In file included from /Users/ben/Downloads/vtk-5.6.1/buildJnilib/Common/vtkAbstractArrayJava.cxx:7:
>>> /Users/ben/Downloads/vtk-5.6.1/Common/vtkJavaUtil.h:20:17: error: jni.h: No such file or directory
>>> In file included from /Users/ben/Downloads/vtk-5.6.1/buildJnilib/Common/vtkAbstractArrayJava.cxx:7:
>>> /Users/ben/Downloads/vtk-5.6.1/Common/vtkJavaUtil.h:24: error: ‘JNIEXPORT’ does not name a type
>>> /Users/ben/Downloads/vtk-5.6.1/Common/vtkJavaUtil.h:26: error: expected initializer before ‘void’
>>> /Users/ben/Downloads/vtk-5.6.1/Common/vtkJavaUtil.h:27: error: expected initializer before ‘char’
>>> /Users/ben/Downloads/vtk-5.6.1/Common/vtkJavaUtil.h:28: error: ‘JNIEXPORT’ does not name a type
>>> /Users/ben/Downloads/vtk-5.6.1/Common/vtkJavaUtil.h:30: error: ‘JNIEXPORT’ does not name a type
>>> /Users/ben/Downloads/vtk-5.6.1/Common/vtkJavaUtil.h:32: error: ‘JNIEXPORT’ does not name a type
>>> ...
>>> 
>>> Can somebody help?
>>> 
>>> Thank you
>>> Ben
>>> 
>>> 
>>> Le 19 oct. 2010 à 10:25, Thiébault Benoît a écrit :
>>> 
>>>> Hi everyone,
>>>> 
>>>> I'm trying to embed VTK in an OSGi bundle. I already successfully created a bundle that supports Linux and I am now concentrating on MacOSX.
>>>> It seems OSGi cannot deal with .dylib libraries and thus I would like to compile VTK with CMake creating .jnilib extensions.
>>>> Renaming the libraries is not sufficient, as their dependencies are stored with respect to the .dylib file.
>>>> 
>>>> For instance:
>>>>> otool -L libvtkCommonJava.jnilib
>>>> libvtkCommonJava.jnilib:
>>>> 	libvtkCommonJava.5.6.dylib (compatibility version 5.6.0, current version 5.6.1)
>>>> 	libvtkCommon.5.6.dylib (compatibility version 5.6.0, current version 5.6.1)
>>>> 	libvtksys.5.6.dylib (compatibility version 5.6.0, current version 5.6.1)
>>>> 	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
>>>> 	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
>>>> 
>>>> Can anyone point me what to do in CMake files to modify the library extensions?
>>>> 
>>>> Kind regards,
>>>> 
>>>> Ben
>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>> 
>>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>> 
>>>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>> 
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>> 
>>> 
>>> _______________________________________________
>>> Powered by www.kitware.com
>>> 
>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>> 
>>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>> 
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>> 
>> 
> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 




More information about the vtkusers mailing list