Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Java et JNI

1 réponse
Avatar
s.dagognet
Bonjour,

J'ai un problème lors de l'appel d'une DLL avec JNI.
voici les codes :

// dll_test.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "stdio.h"
#include "jni.h"

/*BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}*/

JNIEXPORT void JNICALL Java_Test_test(JNIEnv * env, jobject o){
printf("Hello World!");
}


/////// Test.java :

public class Test {
public Test(){ }
private native void test();
static {
System.loadLibrary("dll_test");
}

public static void main(String[] args) {
Test app = new Test();
app.test();
}
}

///////////// Test.h :

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Test */

#ifndef _Included_Test
#define _Included_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Test
* Method: test
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_Test_test
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

A l'exécution j'objtiens :
java.lang.UnsatisfiedLinkError: test
at Test.test(Native Method)
at Test.main(Test.java:29)

Où est le problème ?
Merci.

1 réponse

Avatar
youp
Il faut inclure "Test.h" dans le fichier dll_test.cpp
Ca devrait fonctionner comme ca, enfin,si les variables d'environnement
sont bien placees pour trouver la dll.


youp