Appel de fonctions de bibliothèque natives, obtention de java.lang.UnsatisfiedLinkError?


J'essaie donc d'obtenir cette bibliothèque native ici et de la compiler et de l'exécuter dans mon application Java. Voici l'erreur que je reçois lorsque j'essaie d'exécuter du code à partir de la bibliothèque native:

Exception in thread: java.lang.UnsatisfiedLinkError: package.class.Init(Ljava/lang/String;IIIII)I
    at...
Caused by: java.lang.UnsatisfiedLinkError: package.class.Init(Ljava/lang/String;IIIII)I
    at package.class.Init(Native Method)
    at...

Voici mon processus.

J'ai donc téléchargé MinGW (64 bits, car je me faisais engueuler si c'était 32 bits) et compilé la bibliothèque native comme ceci:

g++ -I"D:\My Programs\Java\jdk1.7.0_67\include" -I"D:\My Programs\Java\jdk1.7.0_67\include\win32" gifflen.cpp -o gifflen.so -shared -fPIC -Wl,--kill-at

Cela m'a donné le gifflen.so fichier que j'utilise comme ça dans mon Java application:

...
private native int Init(String gifName, int w, int h, int numColors, int quality, int frameDelay);
private native void Close();
private native int AddFrame(int[] inArray);

static
{
    System.load("D:/Desktop/gifflen4.so");
}
...

Je ne sais pas ce qui est pertinent et ce qui ne l'est pas, mais voici une partie du sommet de gifflen.cpp , y compris la fonction Init () qui est mentionnée dans l'erreur ci-dessus:

extern "C"
{
JNIEXPORT jint JNICALL Java_org_jiggawatt_giffle_Giffle_Init(JNIEnv *ioEnv, jobject ioThis, jstring gifName, jint w, jint h, jint numColors, jint quality, jint frameDelay);
JNIEXPORT void JNICALL Java_org_jiggawatt_giffle_Giffle_Close(JNIEnv *ioEnv, jobject ioThis);
JNIEXPORT jint JNICALL Java_org_jiggawatt_giffle_Giffle_AddFrame(JNIEnv *ioEnv, jobject ioThis, jintArray inArray);
};

JNIEXPORT jint JNICALL Java_org_jiggawatt_giffle_Giffle_Init(JNIEnv *ioEnv, jobject ioThis, jstring gifName, jint w, jint h, jint numColors, jint quality, jint frameDelay)
{
// code etc...
}
Author: FTLRalph, 2015-03-24

1 answers

Votre code Java n'est pas dans le bon paquet et la bonne classe. Les méthodes natives doivent être dans org.jiggawatt.giffle.Giffle.

 0
Author: Christian Hackl, 2015-03-25 08:01:34