Bonjour à tous,
Je rencontre quelques difficultés à utiliser JNI pour pouvoir effectuer des actions sur le lecteur CD.

Avant toute chose, voici mes différents fichiers sources.

CDdrive.java:
Code : 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
public class CDdrive {
 
    private native void initialize();
 
    public native void open();
 
    private native void dispose();
 
    static{
        System.loadLibrary("CDdrive");
    }
 
    public CDdrive(){
        initialize();
    }
 
    protected void finalize(){
        dispose();
    }
 
    public static void main(String[] args){
        CDdrive lecteur = new CDdrive();
        System.out.println("Le lecteur va s'ouvrir.");
        lecteur.open();
        System.out.println("Le lecteur est ouvert.");
        System.exit(0);
    }
}
CDdrive.h:
Code : 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
30
31
32
33
34
35
36
37
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class CDdrive */
 
#ifndef _Included_CDdrive
#define _Included_CDdrive
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     CDdrive
 * Method:    initialize
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_CDdrive_initialize
  (JNIEnv *, jobject);
 
/*
 * Class:     CDdrive
 * Method:    open
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_CDdrive_open
  (JNIEnv *, jobject);
 
/*
 * Class:     CDdrive
 * Method:    dispose
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_CDdrive_dispose
  (JNIEnv *, jobject);
 
#ifdef __cplusplus
}
#endif
#endif
CDdrive.cpp:
Code : 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
30
31
32
33
34
35
36
37
38
39
40
#include <jni.h>
#include "CDdrive.h"
#include <SDL/SDL.h>
#include <cstdlib>
#include <iostream>
using namespace std;
 
JNIEXPORT void JNICALL Java_CDdrive_initialize(JNIEnv *envir, jobject object)
{
    if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
        fprintf(stderr, "Impossible d'initialiser SDL: %s\n", SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);
}
 
JNIEXPORT void JNICALL Java_CDdrive_open(JNIEnv *envir, jobject object)
{
    SDL_CD *cdrom;
    /* Check for CD drives */
    if(!SDL_CDNumDrives()){
      /* None found */
      fprintf(stderr, "No CDROM devices available\n");
      exit(-1);
    }
 
    /* Open the default drive */
    cdrom=SDL_CDOpen(0);
 
    /* Did if open? Check if cdrom is NULL */
    if(!cdrom){
      fprintf(stderr, "Couldn't open drive: %s\n", SDL_GetError());
      exit(-1);
    }
}
 
JNIEXPORT void JNICALL Java_CDdrive_dispose(JNIEnv *envir, jobject object)
{
    SDL_Quit();
}
J'ai bien compiler le fichier c++ sous forme de librairie dynamique et le JNI semble bien le détecter. Mais l'erreur vient lors de l'appel à la méthode initialize() et j'obtiens l'erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
Exception in thread "main" java.lang.UnsatisfiedLinkError: initialize
   at CDdrive.initialize(Native Method)
   at CDdrive.<init>(CDdrive.java:20)
   at CDdrive.main(CDdrive.java:28)
J'ai beau avoir chercher des heures dans mes fichiers sources, je ne vois pas quelle erreur j'ait pu faire.

Pourriez-vous m'aider?