java.lang.UnsatisfiedLinkError dll.HelloJNI.sayHello()V


While calling a dll from java i was getting this error

Exception in thread "main" java.lang.UnsatisfiedLinkError: dll.HelloJNI.sayHello()V
at dll.HelloJNI.sayHello(Native Method)
at dll.HelloJNI.main(

Here is my java code

 public class HelloJNI {  
 public static void main(String[] args) {
     HelloJNI h = new HelloJNI(); 
     h.sayHello();  // invoke the native method

 static {
         System.load("D://Program Files//Java//jdk1.7.0_40//bin//hello.dll"); // hello.dll (Windows) or (Unixes) 
     catch (UnsatisfiedLinkError e) {
          System.err.println("Native code library failed to load.\n" + e);

   private native void sayHello();


Here is my c code for dll.

am using gcc compiler to generate dll

for MinGWC am using

gcc -Wl,--add-stdcall-alias -I"\include" -I"\include\win32" -shared -o hello.dll HelloJNI.c

#include <jni.h>
#include <stdio.h>
#include "HelloJNI.h"

JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
   printf("Hello World!\n");

I have remove the package dll and while executing i got this error

# A fatal error has been detected by the Java Runtime Environment:
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x610d70b4, pid=1720, tid=1160
# JRE version: Java(TM) SE Runtime Environment (7.0_40-b43) (build 1.7.0_40-b43)
# Java VM: Java HotSpot(TM) Client VM (24.0-b56 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [cygwin1.dll+0xd70b4]
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
# If you would like to submit a bug report, please visit:
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
asked on Stack Overflow Oct 9, 2013 by Bala • edited Oct 9, 2013 by Bala

3 Answers


You have added a package name since you generated the C code. The package name is now dll, but when you generated it, there wasn't one. Redo and adjust your C code accordingly so it agrees with the new .h file.

answered on Stack Overflow Oct 9, 2013 by Marquis of Lorne • edited Oct 9, 2013 by Marquis of Lorne

Remove printf and instead of it try to return some value or string from your cpp file and try to print it from java file.

answered on Stack Overflow Nov 25, 2014 by user80942

try compiling using 64-bit compiler like "x86_64-w64-mingw32-g++".The same error occurred for me and the error is fixed now...

The reason is that either another java instance might be running from your machine or the system architecture does not match with your native code. Try changing that and see if it works.

answered on Stack Overflow Jul 6, 2018 by THE KING • edited Jun 4, 2020 by THE KING

User contributions licensed under CC BY-SA 3.0