java.lang.UnsatisfiedLinkError avec JNI
Bonjour,
j'essaie de faire fonctionner un programme tout simple avec JNI sous Windows. J'arrive à compiler le programme et à produire le fichier .h et la dll, mais quand j'essaie à éxuter le programme, j'ai ce message d'erreur.
Exception in thread "main" java.lang.UnsatisfiedLinkError: afficheCpp
at Bonjour.afficheCpp(Native Method)
at Bonjour.main(Bonjour.java:26)
La partie Java de code fonctionne, mais pas la partie C++.
Le code du programme java c'est
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public class Bonjour {
public native void afficheCpp();
//chargement de la librairie c++ HelloWorld
static {System.loadLibrary("HelloW"); }
public static void main (String[] args)
{
System.out.println("coucou (en java)\n");
new Bonjour().afficheCpp();
}
} |
Le Programme C, c'est
Code:
1 2 3 4 5 6 7 8 9 10
| #include <jni.h>
#include "HelloW.h"
#include <iostream>
using namespace std;
JNIEXPORT void JNICALL Java_Bonjour_afficheCpp (JNIEnv *env, jobject obj)
{
cout<<"Ich heisse Sonja ( en C++)"<<endl;
} |
et le fichier .h, c'est
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| /* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Bonjour */
#ifndef _Included_Bonjour
#define _Included_Bonjour
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Bonjour
* Method: afficheCpp
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Bonjour_afficheCpp
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif |
J'ai déjà essayé plein de choses, mais je ne sais plus quoi faire. Au début j'ai pensé qu'il ne trouve pas la dll, mais si j'efface la dll, j'ai un autre message d'erreur:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no HelloW in java.lib
rary.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at Bonjour.<clinit>(Bonjour.java:19)
Le problème c'est plutôt que le java compiler ne trouve pas la fonctionne afficheCpp dans la .dll. Sur Linux le même programme fonctionne, mais je ne vois pas ce qu'il faut encore changer pour que cela marche.
Si quelqu'un peux m'aider, ce serais super.
Sonja