OVH Cloud OVH Cloud

problème avec JNI

2 réponses
Avatar
cyan
bonjour,

j'obtiens l'erreur suivante quand j'essaie de lancer mon programme java
:

Exception in thread "main" java.lang.UnsatisfiedLinkError: printCpp
at Test.TestJNI.printCpp(Native Method)
at Test.TestJNI.main(TestJNI.java:27)

quelqu'un pourrait il m'expliquer car je ne vois pas le probl=E8me, j'ai
m=EAme v=E9rifi=E9 dans ma DLL et la fonction Java_TestJNI_printCpp est
pr=E9sente.

Merci d'avance.

voici mon code

//TestJNI.java
/////////////////////////
public class TestJNI
{
public native void printCpp();
static
{
System.loadLibrary("MaLib");
}
public static void main(String [] args)
{
new TestJNI().printCpp();
System.out.println("JAVA");
}

}


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

#ifndef _Included_TestJNI
#define _Included_TestJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: TestJNI
* Method: printCpp
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_TestJNI_printCpp
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif


//MaLib.h
////////////////////////
#pragma once

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h" // symboles principaux
#include "TestJNI.h"

// CMaLibApp
// Consultez MaLib.cpp pour l'impl=E9mentation de cette classe
//

class CMaLibApp : public CWinApp
{
public:
CMaLibApp();

// Overrides
public:
virtual BOOL InitInstance();

DECLARE_MESSAGE_MAP()
};


JNIEXPORT void JNICALL Java_TestJNI_printCpp
(JNIEnv *, jclass)
{
printf("C++\n");
}

//MaLib.def
////////////////////////
; MaLib.def : d=E9clare les param=E8tres de module pour la DLL.

LIBRARY "MaLib"

EXPORTS
; Les exportations explicites peuvent =EAtre plac=E9es ici
Java_TestJNI_printCpp

2 réponses

Avatar
Patrix

j'obtiens l'erreur suivante quand j'essaie de lancer mon programme java
:

Exception in thread "main" java.lang.UnsatisfiedLinkError: printCpp
at Test.TestJNI.printCpp(Native Method)
at Test.TestJNI.main(TestJNI.java:27)

quelqu'un pourrait il m'expliquer car je ne vois pas le problème, j'ai
même vérifié dans ma DLL et la fonction Java_TestJNI_printCpp est
présente.



Ta DLL est-elle dans le PATH, ou sinon as-tu positionné la propriété
java.library.path?

Avatar
cyan
non mon path était bien positionné.

J'ai finalement trouvé (ouf), donc pour ceux qui bloqueraient ou
bloqueront sur ce problème, lisez attentivement.

En fait je me suis trompé sur dans la génération du .h

je faisais : javah -jni TestJNI

or : j'avais écrit dans mon .java( et omis de le préciser dans mon
1er post ) : package Test

Il a donc fallut que j'écrive en mode console :
javah -jni Test.TestJNI
*****
voila

merci de ta réponse si rapide Patrix

Yann