Libresource
Home
Search
My Page
Guest -
Login
Navigation
location:
>
Artenum development blog
>
Ben
>
Posts
>
OSGi, VTK and Linux
Contextual Menu
Blog pages
Home
Other blogs
Comments
Download
Posts
Last blog entries
OSGi, VTK and Linux
OSGi, VTK and MacOSX
Edit this menu
Resource Menu
Properties
Security
More actions...
----
Node Information
Create new resource
Delete this resource
Move this resource
Unbind this resource
----
List children
Go to parent
----
search from here
OSGi, VTK and Linux
1 Objectives As introduced in my [http://dev.artenum.com/blog/ben/posts/osgi_vtk_and_macosx|previous article], we have decided to use the [http://www.osgi.org|OSGi] framework at [http://www.artenum.com/EN|Artenum] as the basis of our modular projects. I have already written about how to embed [http://www.vtk.org|VTK], the C++ open source Visualization Toolkit, in an OSGi bundle for Mac OS X. The purpose of this new article is to detail how to do it on Linux. As I already detailed how JNI and OSGi work with native libraries in my previous article, I will not go through these points again. This article is divided in two parts: - __1) Compiling VTK__, a detailed explanation of how to compile VTK on Linux -- a) Hardware and operating system -- b) Prerequisites -- c) Compiling VTK with Java wrapping - __2) Embedding VTK in an OSGi bundle__, describing Linux specific constraints encountered. -- a) Prerequisites -- b) Embedding VTK in an OSGi bundle 1 1) Compiling VTK 1.1 a) Hardware and operating system For this article, I have used a clean [http://www.ubuntu.com|Ubuntu] 10.10 64 bits distribution installed on my MacBook Pro 3.1 with 2.2GHz Intel Core 2 Duo processors. At installation, I have selected the option to automatically download the updates during installation. When I first started opened a session, I was thus proposed to install all updates, including Embedded GNU C Library (libc6 version 2.12.1) that is required to compile VTK. 1.1 b) Prerequisites Here are the prerequisites to compile the VTK library: - Sun JDK 6: to install Sun JDK, use the command lines below. {code} > sudo add-apt-repository "deb http://archive.canonical.com/ubuntu maverick partner" > sudo apt-get update > sudo apt-get install sun-java6-jdk {code} The check that the install was successful with the command: {code} > java -version {code} - g++ to compile C++ code: {code} > sudo apt-get install g++ {code} - OpenGL: {code} > sudo apt-get install libgl1-mesa-dev {code} - X11 toolkit intrinsics library (development headers): {code} > sudo apt-get install libxt-dev {code} - CMake, the cross-platform make, used to generate makefiles to compile VTK. To install it, use the command lines below. {code} > sudo apt-get install cmake-curses-gui {code} \\ - [http://vtk.org/VTK/resources/software.html#latest|VTK latest source code] (5.6.1 at the time this article was written). I have created a __vtk-5.6.1-src__ directory in my root folder and unzipped the VTK archive there (beware: unzipping does not create a VTK directory but extract all data in place…). I have then created a __build__ directory inside this source directory 1.1 c) Setting the compilation First, create a __vtk-5.6.1__ directory in your home folder. This is where VTK will be installed. Then go to the __~/vtk-5.6.1-src/build__ directory and type: {code} > ccmake -i .. {code} A basic graphical user interface will be displayed in the terminal, as shown in figure below: {image:../../download/cmake-gui-linux_png} Type __c__ to configure CMake. It will look for the compilers installed on the machine, the JVM path, etc. You will then have to select the compilation options, the install directory, the build type, etc. Here is the configuration I used (in bold are the important elements to check): {code} BUILD_EXAMPLES OFF __BUILD_SHARED_LIBS ON__ BUILD_TESTING OFF CMAKE_BACKWARDS_COMPATIBILITY 2.4 __CMAKE_BUILD_TYPE Release CMAKE_INSTALL_PREFIX /home/atrouche/vtk-5.8.0__ VTK_DATA_ROOT VTK_DATA_ROOT-NOTFOUND VTK_EXTRA_COMPILER_WARNINGS OFF VTK_LARGE_DATA_ROOT VTK_LARGE_DATA_ROOT-NOTFOUND VTK_USE_CHARTS ON VTK_USE_GEOVIS ON VTK_USE_INFOVIS ON VTK_USE_N_WAY_ARRAYS ON __VTK_USE_PARALLEL ON__ VTK_USE_QT OFF VTK_USE_RENDERING ON VTK_USE_TEXT_ANALYSIS OFF VTK_USE_VIEWS ON __VTK_WRAP_JAVA ON__ VTK_WRAP_PYTHON OFF VTK_WRAP_PYTHON_SIP OFF VTK_WRAP_TCL OFF {code} Type __c__ again to validate those settings (you may have to do it twice) and then __g__ to generate the makefiles. Sometimes, other flags may be necessary (they are accessible by typing __t__ in ccmake): - depending on the machine and what you have already installed on, you may have to indicate the correct compiler by modifying the two following lines (with your path to g++/gcc): {code} CMAKE_CXX_COMPILER /usr/bin/g++ CMAKE_C_COMPILER /usr/bin/gcc {code} - if you have an error when typing __c__ such as "JAVA_AWT_INCLUDE_PATH NOT FOUND", you have to define the java following flags (here is an exemple I used with Java 8, path may vary depending on the java version you have, check every line). Also, it is a good way to check that cmake is using the correct java version (seeing the path it found): {code} JAVA_AWT_INCLUDE_PATH /usr/lib64/jvm/java/include JAVA_AWT_LIBRARY /usr/lib64/jvm/java/jre/lib/amd64/libjawt.so JAVA_INCLUDE_PATH /usr/lib64/jvm/java/include JAVA_INCLUDE_PATH2 /usr/lib64/jvm/java/include/linux JAVA_JVM_LIBRARY /usr/lib64/jvm/java/jre/lib/amd64/server/libjvm.so Java_IDLJ_EXECUTABLE /usr/lib64/jvm/java/bin/idlj Java_JARSIGNER_EXECUTABLE /usr/lib64/jvm/java/bin/jarsigner Java_JAR_EXECUTABLE /usr/lib64/jvm/java/bin/jar Java_JAVAC_EXECUTABLE /usr/lib64/jvm/java/bin/javac Java_JAVADOC_EXECUTABLE /usr/lib64/jvm/java/bin/javadoc Java_JAVAH_EXECUTABLE /usr/lib64/jvm/java/bin/javah Java_JAVA_EXECUTABLE /usr/lib64/jvm/java/bin/java {code} 1.1 d) Compiling VTK with Java wrapping You can now build VTK with the command line: {code} > make -j 2 {code} Where the "-j 2" option indicates the number of processors on which you want the compilation to be performed This step might take a while (up to one or two hours depending on your configuration). If during the compilation process, you encounter the error "‘GLintptr’ has not been declared", you need to reopen ccmake and add the following flags to these lines: {code} CMAKE_CXX_FLAGS -DGLX_GLXEXT_LEGACY CMAKE_C_FLAGS -DGLX_GLXEXT_LEGACY {code} Finally, you have to install the shared libraries to your installation directory with the command line: {code} > make install {code} (If you chose another directory than the one I suggested in your home folder, you might need to use __sudo__ to install VTK). 1 2) Embedding VTK in an OSGi bundle 1.1 a) Prerequisites - The sample project provided here are built with [http://maven.apache.org|Maven]. To install it, use the command line: {code} > sudo apt-get install maven2 {code} - You will also need an Integrated Development Environment, such as [http://www.eclipse.org|Eclipse], which can be downloaded here: [http://www.eclipse.org/downloads]. It is preferable to download Eclipse from Eclipse website than with Ubuntu Software Centre, which provides an outdated version of Eclipse. You should also install [http://m2eclipse.sonatype.org/installing-m2eclipse.html|m2eclipse plugin] to import and manage Maven projects with Eclipse. - Finally, to run the OSGi Framework and execute the VTK bundle, you will need an implementation of the framework. Two popular open-source implementations are [http://download.eclipse.org/equinox/|Equinox] and [http://felix.apache.org/site/downloads.cgi|Felix]. 1.1 b) Embedding VTK in an OSGi bundle The OSGi bundle embedding VTK for Linux is very similar to the one in my [http://dev.artenum.com/blog/ben/posts/osgi_vtk_and_macosx|previous article]. You can download the project (with the compiled VTK libraries) here: [../../download/test-osgi-vtk-linux64b_zip?action=download&nodecorator]. In this project, we have created two classes: - __org.test.vtk.osgi.TestVTK__ is the same JFrame that contains the method ~~start()~~ to initialize a vtkPanel containing the 3D cone. It also contains the ~~stop()~~method called when the bundle is stopped. - __org.test.vtk.osgi.Activator__ is the ~~BundleActivator~~ class that will be called by OSGi when the bundle is started or stopped. It statically loads the VTK libraries one by one, in the correct order of their dependencies, as shown below: {code} static { System.loadLibrary("vtkproj4"); System.loadLibrary("vtkalglib"); System.loadLibrary("vtksys"); System.loadLibrary("vtkCommon"); System.loadLibrary("vtkFiltering"); System.loadLibrary("vtkexpat"); System.loadLibrary("vtkjpeg"); System.loadLibrary("vtkzlib"); System.loadLibrary("vtklibxml2"); System.loadLibrary("vtktiff"); System.loadLibrary("vtkpng"); System.loadLibrary("vtksqlite"); System.loadLibrary("vtkmetaio"); System.loadLibrary("vtkNetCDF"); System.loadLibrary("vtkDICOMParser"); System.loadLibrary("vtkNetCDF_cxx"); System.loadLibrary("vtkIO"); System.loadLibrary("vtkImaging"); System.loadLibrary("vtkverdict"); System.loadLibrary("vtkGraphics"); System.loadLibrary("vtkfreetype"); System.loadLibrary("vtkftgl"); System.loadLibrary("vtkGenericFiltering"); System.loadLibrary("vtkRendering"); System.loadLibrary("vtkexoIIc"); System.loadLibrary("Cosmo"); System.loadLibrary("VPIC"); System.loadLibrary("vtkParallel"); System.loadLibrary("vtkHybrid"); System.loadLibrary("vtkWidgets"); System.loadLibrary("vtkVolumeRendering"); } {code} We can execute the bundle in Equinox, for instance: {code} # First we delete the cache folder contraining previously loaded bundles rm -rf configuration/org.eclipse.osgi configuration *.log \# Then we execute Equinox with the argument -Xcheck:jni to see JNI-related errors java -Xcheck:jni -jar org.eclipse.osgi_3.6.1.R36x_v20100806.jar -console osgi> install file:/home/ben/workspace/test-osgi-vtk-linux64b/target/test-osgi-vtk-linux64b-1.0-SNAPSHOT.jar osgi> start 1 {code} We obtain the result illustrated in figure below: {image:../../download/linux-cone_png} At some point in my attempts to embed VTK in a bundle on Linux, I have had an ~~UnsatisfiedLinkError~~ where the JVM was looking for the shared library libmawt.so. This is a know bug of the JVM ([http://bugs.sun.com/view_bug.do?bug_id=6539705]) that I fixed by adding the path to the library in the LD_LIBRARY_PATH. {code} export LD_LIBRARY_PATH=/usr/lib/jvm/java-6-sun-1.6.0.21/jre/lib/i386/xawt {code} In the version of the bundle that is provided above, this phenomenon however did not occur anymore. I don't really know what I did to fix it, but I will not complain as far as it works :-). I let this workaround anyway in case someone one day encounters the problem. 1 Conclusion As we have seen, we have successfully created a VTK OSGi bundle for Linux. We have reviewed in detail the prerequisites of the compilation of VTK on Linux and explained the compilation process. We also provided an example of a VTK bundle running on Linux 64bits. ---- {resource:../../comments/OSGi_Linux_and_VTK}
Last edited by Arnaud Trouche at Jan 29, 2016 2:16 PM -
Edit content
-
View history
-
View source