bonjour,
j'ai suivi ce tutoriel pour créer mon projet JNI sous Netbeans. Cependant j'ai une exception java.lang.UnsatisfiedLinkError qui est levée lors de son exécution.
Je ne vois pas où est mon erreur.
J'ai placé dans le dossier DLL du projet java tous les fichiers créés par la compilation de la librairie :
-HelloWorldNative.dll
-libHelloWorldNative.a
-libHelloWorldNative.def
ainsi que le HelloWorldNative.h
Mon code java :
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package helloworld; public class Main { private native void nativePrint(); try { System.load("C:\\Documents and Settings\\Mes documents\\" + "Doc_Java\\HelloWorld\\dll\\HelloWorldNative.dll"); } catch (UnsatisfiedLinkError e) { System.out.println("Err 1 " + e.getMessage()); } public static void main(String[] args) { try { new Main().nativePrint(); } catch (UnsatisfiedLinkError e) { System.out.println("Err 2 " + e.getMessage()); } } }
Mon code C. J'utilise Code::Block. Le fichier d'entête a été généré par javah
Code c : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 #include <jni.h> #include <stdio.h> #include "HelloWorldNative.h" JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint (JNIEnv *env, jobject obj) { printf("\nHello World from C\n"); }
Code c : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class helloworld_Main */ #ifndef _Included_helloworld_Main #define _Included_helloworld_Main #ifdef __cplusplus extern "C" { #endif /* * Class: helloworld_Main * Method: nativePrint * Signature: ()V */ JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif
Partager