Ask Your Question

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) and opencv_java.jar

So far so good, but when i try to load the 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

did i miss something or is this correct ?

String libName = "";
libName = "";
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:


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 "" 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 ?

edit retag flag offensive close merge delete


can you try to rename or copy to ?

( 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 directly ? Why am i getting the ?

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

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

ady_e_n gravatar image

Update*: I have partially found my answer here:

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:


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

edit flag offensive delete link more


Hi, I am getting the same problem linking the compiled 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


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

Seen: 6,383 times

Last updated: Jun 18 '18