Ask Your Question
0

failed to use System.loadLibrary(Core.NATIVE_LIBRARY_NAME) on Raspberry pi

asked 2018-06-16 10:36:03 -0600

ady_e_n gravatar image

Hi All,

I compiled the opencv latest sources on my Raspberry pi (for java) and i got the following files (among others) libopencv_java400.so and opencv_java.jar

So far so good, but when i try to load the libopencv_java400.so library in my java program, it fails to do so saying that the source can't be found.

I have tried several ways to load the file and i get the following errors : System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

returns error (in debug mode):
Source not found.

Additionally, i have found that if i look inside the Core class in org.opencv.core , the return for this is :
private static String getNativeLibraryName() { return "opencv_java400"; } and not libopencv_java400.so

did i miss something or is this correct ?

String libName = "";
libName = "libopencv_java400.so";
System.load(new File("/home/pi/workspace/ro.romaniasoft.FRI/libs/".concat(libName)).getAbsolutePath());

returns error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library:
/home/pi/workspace/ro.romaniasoft.FRI/libs/libopencv_java400.so


System.load("/home/pi/opencv/build/lib/libopencv_java400.so");

returns error (in debug mode):
Source not found.


I have added the native path in my Java Build Path - > opencv_java.jar -> native library location to "/home/pi/opencv/build/lib"

I also tried to copy the "libopencv_java400.so" to "/usr/lib/jvm/java-8-openjdk-armhf/jre/lib/arm"

Apparently Nothing works. I'm stuck at this Load Library step.

Could you please help me ?
Thanks
Regards

edit retag flag offensive close merge delete

Comments

can you try to rename or copy libopencv_java400.so to opencv_java400.so ?

( getNativeLibraryName() is correct, the name of your so isn't )

berak gravatar imageberak ( 2018-06-17 01:35:32 -0600 )edit

Hi Berak, yes, i also tried renaming the file. Tired making several copies of both files in various locations. still nothing.

When executing the cmake command, shouldn't the script generate the .so file under the name opencv_java400.so directly ? Why am i getting the libopencv_java400.so ?

Thanks Regards

ady_e_n gravatar imageady_e_n ( 2018-06-17 11:34:15 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-06-18 12:18:07 -0600

ady_e_n gravatar image

Update*: I have partially found my answer here: https://github.com/opencv/opencv/issu...

The problem seams to be due to building without the flag : -DWITH_FFMPEG=OFF

Apparently, there caused a problem and prevented the System.LoadLibrary() to fail when using it in my java class.

Set this flag again in Cmake, compiled everything and now it works fine.

There is however another workaround that i didn't understood, and maybe some of you guys could help me and it goes like this:

building ffmpeg from src with "--disable-libopenmpt"

What did he want to say by that ? how can i build ffmpeg from src ?

Sorry for the noob question

I'm also going to put cmake command line that i used to compile on Raspberry Pi 3:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_EXAMPLES=OFF -D BUILD_DOCS=OFF -D BUILD_SHARED_LIBS=OFF -D OPENCV_EXTRA_MODULES_PATH="$HOME/opencv_contrib/modules" /home/pi/opencv/build/ ..

Anyway, hope this helps future guys that might run into this problem in the future. Regards

edit flag offensive delete link more

Comments

Hi, I am getting the same problem linking the compiled opencv400.so from my raspberry into my java project. I am a bit confused with your answer, you say "The problem seams to be due to building without the flag : -DWITH_FFMPEG=OFF" and in the cmake command line you use you don't put it. So how is the command that worked for you?

Santiago-Molina gravatar imageSantiago-Molina ( 2018-06-19 11:12:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-16 10:36:03 -0600

Seen: 6,967 times

Last updated: Jun 18 '18