1
votes

I'm on Ubuntu 13.10.

I'd like to run Visualization Toolkit (VTK) in my sbt project.

I've installed the libvtk over synaptic package manager. I can run my class with the VTK example without problems. But when I try to run it over the SBT via the run command, I get an UnsatisfiedLinkError.

I tried several things. This means adding vtk.jar into the lib folder of the project and trying several sbt dependencies for vtk from Artenum.

I like to run the whole stuff in sbt, because I use some other stuff for testing and so on. Only compiling the class with the vtk dependency inside is no option for me.

Setting paths and so on I tried also. But I mean, I can install a whole lot of other dependencies without setting paths in my OS.

An alternative could be to find a working graphical tool like vtk which is good to run as a dependency in Java/Scala.

This is my build.sbt:

name := "selfoo"

version := "1.0"

scalaVersion := "2.10.3"

scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")

resolvers ++= Seq(
  "Sonatype OSS"  at "https://oss.sonatype.org/content/repositories/releases",
  "Typesafe"      at "http://repo.typesafe.com/typesafe/releases",
  "artenum"       at "http://maven.artenum.com/content/groups/public"
)

libraryDependencies ++= Seq(
  "com.typesafe.akka"       %% "akka-actor"     % "2.2.1",
  "com.typesafe.akka"       %% "akka-remote"    % "2.2.1",
  "com.typesafe.slick"      %% "slick"          % "1.0.1",
  "net.liftweb"             %% "lift-json"      % "2.5.1",
  // "com.h2database"       %% "h2"             % "1.3.166",
  // "com.googlecode.lanterna" %  "lanterna"       % "2.1.6",
  "commons-net"             %  "commons-net"    % "3.3",
  "jline"                   %  "jline"          % "2.11",
  "org.apache.mina"         %  "mina-core"      % "2.0.4",
  "org.apache.ftpserver"    %  "ftplet-api"     % "1.0.6",
  "org.apache.ftpserver"    %  "ftpserver-core" % "1.0.6",
  "org.slf4j"               %  "slf4j-api"      % "1.6.4",
  "org.scala-lang"          %  "scala-swing"    % "2.10+",
  "vtk"                     %  "vtk"            % "5.8.0",
  "org.slf4j"               %  "slf4j-simple"   % "1.6.4")

And this is the stacktrace i get:

[info] Compiling 1 Scala source to /root/IdeaProjects/selfoo/target/scala-2.10/classes...
[info] Running ScalaCone 
[error] (run-main) java.lang.UnsatisfiedLinkError: vtk.vtkPoints.VTKInit()J
java.lang.UnsatisfiedLinkError: vtk.vtkPoints.VTKInit()J
    at vtk.vtkPoints.VTKInit(Native Method)
    at vtk.vtkObject.<init>(vtkObject.java:97)
    at vtk.vtkPoints.<init>(vtkPoints.java:166)
    at ScalaCone$.<init>(ScalaCone.scala:12)
    at ScalaCone$.<clinit>(ScalaCone.scala)
    at ScalaCone.main(ScalaCone.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
[trace] Stack trace suppressed: run 'last compile:run' for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
    at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run 'last compile:run' for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 3 s, completed 21.03.2014 13:13:02

I try to run the example ScalaCone from http://ij-plugins.sourceforge.net/vtk-examples/ScalaCone.html

1
Could you include build.sbt in your question? Could you add the stacktrace? - Jacek Laskowski
Hi Jacek, I edited my post. Now you should see the build.sbt and my stacktrace. I also added the URL where you can find my vtk example, which I try to run. - Robert

1 Answers

1
votes

As of today, vtk is not listed on maven-central. Due to its machine-dependent parts I doubt that it ever will be (since having compiled object code in a jar file somewhat violates the idea of platform independent code - yes I am aware of things like swt).

That being said, the simplest solution would be to include the vtk java interface directly in your project as a thirdparty element.

If you look into the wrapping/java folder of the source distribution, you will find some *.in files that contain macros expanded by cmake. These you would have to adapt in a way to use your system-installed vtk library. The rest is just plain java and you should be able to reuse it.

I am aware that this is not the best solution, but it should allow you to remain fairly platoform independent (you only have to load this shared lib). On the other hand, if platform independence is not your concern, I humbly suggest to drop Java in the first place ;).