java.lang.UnsatisfiedLinkError - JNI -


i keep getting java.lang.unsatisfiedlinkerror error every time run program. have native, wrapper, , program call native through wrapper.

main.h

#ifndef __main_h__ #define __main_h__  #include <windows.h> #ifdef build_dll     #define dll_export __declspec(dllexport) #else     #define dll_export __declspec(dllimport) #endif  #include<jni.h> #include<iostream>  using namespace std;  extern "c" {  jniexport void jnicall native_messagebox(string text, string title);  }  #endif 

main.cpp

#include "main.h"  #include<windows.h> #include<iostream>  using namespace std;  jniexport void jnicall msgbox(string text, string title) {     messagebox(null, text.c_str(), title.c_str(), mb_ok); }  extern "c" dll_export bool apientry dllmain(hinstance hinstdll, dword fdwreason, lpvoid lpvreserved) {     switch (fdwreason)     {         case dll_process_attach:             break;          case dll_process_detach:             break;          case dll_thread_attach:             break;          case dll_thread_detach:             break;     }     return true; } 

wrapper.java

public class wrapper {    private static file nativefile = null;         static    {             //architecturereader , osreader classes made read cpu                           //bits , os     architecturetype archtype = architecturereader.getarcitecture();     ostype ostype = osreader.getos();      string filename = "c:/native-";      if (ostype == ostype.windows)     {         if (archtype == architecturetype.bits_32)             filename += "win32";         else if (archtype == architecturetype.bits_64)             filename += "win64";         else             system.exit(1);     }     else         system.exit(1);      nativefile = new file(filename + ".dll");     if (!nativefile.exists())         system.exit(1);      system.load(filename); //this exception thrown }  private static native void native_messagebox(string text, string title); public static void mesagebox(string text, string title) {     native_messagebox(text, title); }  public static string getnativepath() {     return nativefile.getabsolutepath(); } } 

main.java

public class main { public static void main(string[] args) {     wrapper.messagebox("testing jni", "jni"); } } 

the native built using mingw 64 bit. anyway, don't why error. help?????

i think problem jni signature doesn't match. is:

jniexport void jnicall native_messagebox(string text, string title); 

should like:

jniexport void jnicall java_com_example_wrapper_native_messagebox(string text, string title); 

where, java_com_example should replaced package name (. replace _ in package name).

or

i suggest generate native function signature , declaration using javah -jni option available in java.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -