Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.UnsatisfiedLinkError: no jniopencv_videoio in java.library.path due to java.lang.UnsatisfiedLinkError: ... (libgtk-x11-2.0.so.0) #14

Closed
RoiViber opened this issue Jan 2, 2017 · 7 comments

Comments

@RoiViber
Copy link

RoiViber commented Jan 2, 2017

Hi,

I'm running scala (compiled using sbt) app that uses several OpenCV's functionalities. Eventually I managed to run some of them, but I still encounter the following exception:

Name: java.lang.NoClassDefFoundError
Message: Could not initialize class org.bytedeco.javacpp.opencv_objdetect$CascadeClassifier
StackTrace:

Notes:

  1. My project/plugins.sbt file looks like this:
logLevel := Level.Warn
resolvers += Resolver.sonatypeRepo("releases")
addSbtPlugin("org.bytedeco" % "sbt-javacv" % "1.12")
  1. My build.sbt looks like this:
name := "..."
version := "1.0"
scalaVersion := "2.11.8"
javaCppPresetLibs ++= Seq("opencv" -> "3.1.0", "ffmpeg" -> "3.1.2")
javaCppPlatform := Seq("linux-x86_64")
  1. I'm coding+debugging on Windows machine where everything runs smoothly. Then I tried adding the linux-x86_64 platform to the build.sbt as in (2) and use sbt-assembly to package my linux-ready jar. I uploaded that jar into my linux cluster, then cloned the 3.1.0 version of opencv from https://github.com/Itseez/opencv and ran cmake, make and make install.

  2. Finally, in scala, this piece of code works great (uses org.bytedeco.javacpp.opencv_imgcodecs & org.bytedeco.javacpp.opencv_imgproc):

import org.bytedeco.javacpp.BytePointer
import org.bytedeco.javacpp.opencv_core.{Mat, _}
import org.bytedeco.javacpp.opencv_imgcodecs._
import org.bytedeco.javacpp.opencv_imgproc._
import org.bytedeco.javacpp.opencv_objdetect.CascadeClassifier
 
val bytes = ByteBuffer.wrap( /* some Byte array */ )
val imgCvMat = cvDecodeImageM(cvMat(1, bytes .array().length, CV_8UC1, new BytePointer(bytes )))
val imgMat = cvarrToMat(imgCvMat)

while this code:

val faceCascade = new org.bytedeco.javacpp.opencv_objdetect.CascadeClassifier( /* path to xml of classifier configuration */ )

fails with the following exception:

java.lang.UnsatisfiedLinkError: no jniopencv_videoio in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:784)
at org.bytedeco.javacpp.Loader.load(Loader.java:586)
at org.bytedeco.javacpp.Loader.load(Loader.java:503)
at org.bytedeco.javacpp.opencv_videoio.(opencv_videoio.java:14)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.bytedeco.javacpp.Loader.load(Loader.java:558)
at org.bytedeco.javacpp.Loader.load(Loader.java:503)
at org.bytedeco.javacpp.opencv_objdetect$CascadeClassifier.(opencv_objdetect.java:566)
... 52 elided
Caused by: java.lang.UnsatisfiedLinkError: /home/hadoop/.javacpp/cache/mlageinf.jar/org/bytedeco/javacpp/linux-x86_64/libjniopencv_videoio.so: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:767)
... 60 more

Note that theeres a missing libgtk-x11-2.0.so.0 - and I can't figure out what to do here

@lloydmeta
Copy link
Member

lloydmeta commented Jan 2, 2017

That's strange, I have not seen that error before. In the interest of being thorough, can you make sure you're using the latest JavaCPP by setting the following?

javaCppVersion := "1.3.1"

Also, ffmpeg's latest version is "3.2.1" I believe.

It might be possible that on that platform (linux-x86_64) the shared library object wasn't packaged with the presest jar. @saudet any idea?

@RoiViber
Copy link
Author

RoiViber commented Jan 2, 2017

@lloydmeta thanks for the quick reply. I tried adding the version argument, same result here.
I'm using Amazon's AWS machines, and they have their own linux distribution so I also don't seem to find any way of installing this specific gtk version manually.

@RoiViber
Copy link
Author

RoiViber commented Jan 2, 2017

btw, looking at /myjar.jar/org/bytedeco/javacpp/linux-x86_64/ i have a a lot of libjni*.so files, none of them contain "gtk", so apparently it isn't packaged.

@saudet
Copy link
Member

saudet commented Jan 3, 2017

GTK comes preinstalled with pretty much any Linux distribution... except the one from Amazon that is? So it looks like we might have to do something about that. As usual, contributions are welcome!

@lloydmeta
Copy link
Member

lloydmeta commented Jan 3, 2017

I'm closing this issue for now because it doesn't seem to be related to the SBT plugin.

The discussion should probably continue on the javacpp-presets project, or this PR.

@LtHummus
Copy link

LtHummus commented Nov 7, 2021

For anyone that stumbles upon this later looking for answers:

If you are on Amazon Linux 2, sudo yum install gtk2-devel

@saudet
Copy link
Member

saudet commented Nov 8, 2021

Duplicate of bytedeco/javacpp-presets#593

@saudet saudet marked this as a duplicate of bytedeco/javacpp-presets#593 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants