javac MaClasse.java |
javah MaClasse |
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class MaClasse */ /* * Class: MaClasse * Method: procedure * Signature: ()V */ JNIEXPORT void JNICALL Java_MaClasse_procedure (JNIEnv *, jclass); |
-Irép -Irép/linux |
gcc -Wall -shared -o libbiblio.so biblio.o |
setenv LD_LIBRARY_PATH . |
java MaClasse |
MaClasse.java | biblio.c |
---|---|
// MaClasse.java public class MaClasse { static { System.loadLibrary( "biblio" ); } native public static void cProcedure(); public static void main( String [] args ) { System.out.println( "affichage java" ); cProcedure(); } // main() } // Java2C |
/* biblio.c */ #include <stdio.h> #include "MaClasse.h" JNIEXPORT void JNICALL Java_MaClasse_cProcedure ( JNIEnv * env, jclass cla ) { printf( "affichage c\n" ); } /* ..._cProcedure() */ |
CLASSE = MaClasse PROGC = biblio # # adapter la ligne ci-dessous en fonction du PC INCDIR = /usr/lib/jdk1.5.0v9/include #INCDIR = /usr/java/j2sdk1.4.2/include # CFLAGS = -std=c99 -pedantic -W -Wall IFLAGS = -I$(INCDIR) -I$(INCDIR)/linux LFLAGS = -shared all : $(CLASSE).class lib$(PROGC).so %.class : %.java javac $< javah $(basename $<) %.c : %.h touch $@ %.o : %.c gcc $(CFLAGS) $(IFLAGS) -o $@ -c $< lib%.so : %.o gcc $(LFLAGS) -o $@ $< @echo ____________________ Tapez la ligne suivante avant la premiere execution : @echo ____________________ setenv LD_LIBRARY_PATH . #.SECONDARY : $(PROGC).o TOCLEAN = $(CLASSE).h $(PROGC).o *~ clean : rm -f $(TOCLEAN) cleanall : rm -f lib$(PROGC).so $(CLASSE).class $(TOCLEAN) |