Commit 31ffff63 authored by Martin Deinhofer's avatar Martin Deinhofer
Browse files

migrated makefile.windows to support jdk8 and jdk10

moved jni/makefile.windows to root directory
adapted README.md to reflect new build commands (specifying the respective makefile)
modfied jni/HelloJNI.c to include java_exercises7_1_1_HelloJNI.h instead of HelloJNI.h
parent e1659571
...@@ -25,7 +25,9 @@ At times, it is necessary to use native codes (C/C++) to overcome the memory man ...@@ -25,7 +25,9 @@ At times, it is necessary to use native codes (C/C++) to overcome the memory man
Building the project involves two steps Building the project involves two steps
1. Building the Java code and the native code using the make targets: 1. Building the Java code and the native code using the make targets:
* Command line:```make``` * **Linux**:```make -f makefile.linux all```
* **Windows**:```make -f makefile.windows all```
# Run project # Run project
......
#include <jni.h> #include <jni.h>
#include <stdio.h> #include <stdio.h>
#include "HelloJNI.h" #include "java_exercises7_1_1_HelloJNI.h"
// Implementation of native method sayHello() of HelloJNI class // Implementation of native method sayHello() of HelloJNI class
JNIEXPORT void JNICALL Java_java_1exercises7_11_11_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) { JNIEXPORT void JNICALL Java_java_1exercises7_11_11_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
......
# Define a variable for classpath # Define a variable for classpath
CLASS_PATH = ./bin CLASS_PATH = ./bin
JAVA_HOME=/usr/lib/jvm/default-java/ JAVA_HOME=/usr/lib/jvm/default-java/
JNI_DIR=./jni JNI_DIR=./jni
SRC_DIR=./src SRC_DIR=./src
# Define a virtual path for .class in the bin directory # Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH) vpath %.class $(CLASS_PATH)
all : $(JNI_DIR)/libhello.so $(JNI_DIR)/libjava_exercises7_2_1_HelloJNI.so all : $(JNI_DIR)/libhello.so $(JNI_DIR)/libjava_exercises7_2_1_HelloJNI.so
# Targets for java_exercises_7_1_1 # Targets for java_exercises_7_1_1
# $@ matches the target, $< matches the first dependancy # $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/libhello.so : $(JNI_DIR)/HelloJNI.o $(JNI_DIR)/libhello.so : $(JNI_DIR)/HelloJNI.o
gcc -W -shared -o $@ $< gcc -W -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy # $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/HelloJNI.o : $(JNI_DIR)/HelloJNI.c $(JNI_DIR)/HelloJNI.h $(JNI_DIR)/HelloJNI.o : $(JNI_DIR)/HelloJNI.c $(JNI_DIR)/HelloJNI.h
gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I"$(JNI_DIR)" -c $< -o $@ gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I"$(JNI_DIR)" -c $< -o $@
# $* matches the target filename without the extension # $* matches the target filename without the extension
$(JNI_DIR)/HelloJNI.h : $(JNI_DIR)/HelloJNI.h :
javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_1_1/HelloJNI.java javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_1_1/HelloJNI.java
# Targets for java_exercises_7_2_1 # Targets for java_exercises_7_2_1
# $@ matches the target, $< matches the first dependancy # $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/libjava_exercises7_2_1_HelloJNI.so : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.o $(JNI_DIR)/libjava_exercises7_2_1_HelloJNI.so : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.o
gcc -W -shared -o $@ $< gcc -W -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy # $@ matches the target, $< matches the first dependancy
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.o : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.c $(JNI_DIR)/java_exercises7_2_1_HelloJNI.h $(JNI_DIR)/java_exercises7_2_1_HelloJNI.o : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.c $(JNI_DIR)/java_exercises7_2_1_HelloJNI.h
gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I"$(JNI_DIR)" -c $< -o $@ gcc -I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/linux" -I"$(JNI_DIR)" -c $< -o $@
$(JNI_DIR)/java_exercises7_2_1_HelloJNI.h : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.h :
javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_2_1/HelloJNI.java javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_2_1/HelloJNI.java
clean : clean :
rm -Rf $(JNI_DIR)/*.h $(JNI_DIR)/*.o $(JNI_DIR)/*.so $(JNI_DIR)/*.dll $(CLASS_PATH)/* rm -Rf $(JNI_DIR)/*.h $(JNI_DIR)/*.o $(JNI_DIR)/*.so $(JNI_DIR)/*.dll $(CLASS_PATH)/*
\ No newline at end of file
# Define a variable for classpath # Define a variable for classpath
CLASS_PATH = ../bin CLASS_PATH = bin
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_131 # Either set JAVA_HOME as system-wide windows environment variable or set it here
#JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_131
# Define a virtual path for .class in the bin directory JNI_DIR=jni
vpath %.class $(CLASS_PATH) SRC_DIR=src
all : hello.dll java_exercises7_2_1_HelloJNI.dll # Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
# Targets for java_exercises_7_1_1
# $@ matches the target, $< matches the first dependancy all : $(JNI_DIR)/hello.dll $(JNI_DIR)/java_exercises7_2_1_HelloJNI.dll
hello.dll : HelloJNI.o
gcc -Wl,--add-stdcall-alias -shared -o $@ $< # Targets for java_exercises_7_1_1
# $@ matches the target, $< matches the first dependancy
# $@ matches the target, $< matches the first dependancy $(JNI_DIR)/hello.dll : $(JNI_DIR)/HelloJNI.o
HelloJNI.o : HelloJNI.c HelloJNI.h gcc -Wl,--add-stdcall-alias -shared -o $@ $<
gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -c $< -o $@
# $@ matches the target, $< matches the first dependancy
# $* matches the target filename without the extension $(JNI_DIR)/HelloJNI.o : $(JNI_DIR)/HelloJNI.c $(JNI_DIR)/HelloJNI.h
HelloJNI.h : java_exercises7_1_1/HelloJNI.class gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -I"$(JNI_DIR)" -c $< -o $@
javah -o HelloJNI.h -classpath $(CLASS_PATH) java_exercises7_1_1.$*
# $* matches the target filename without the extension
# Targets for java_exercises_7_2_1 $(JNI_DIR)/HelloJNI.h :
# $@ matches the target, $< matches the first dependancy javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_1_1/HelloJNI.java
java_exercises7_2_1_HelloJNI.dll : java_exercises7_2_1_HelloJNI.o
gcc -Wl,--add-stdcall-alias -shared -o $@ $< # Targets for java_exercises_7_2_1
# $@ matches the target, $< matches the first dependancy
# $@ matches the target, $< matches the first dependancy $(JNI_DIR)/java_exercises7_2_1_HelloJNI.dll : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.o
java_exercises7_2_1_HelloJNI.o : java_exercises7_2_1_HelloJNI.c java_exercises7_2_1_HelloJNI.h gcc -Wl,--add-stdcall-alias -shared -o $@ $<
gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -c $< -o $@
# $@ matches the target, $< matches the first dependancy
java_exercises7_2_1_HelloJNI.h : java_exercises7_2_1/HelloJNI.class $(JNI_DIR)/java_exercises7_2_1_HelloJNI.o : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.c $(JNI_DIR)/java_exercises7_2_1_HelloJNI.h
javah -classpath $(CLASS_PATH) java_exercises7_2_1.HelloJNI gcc -I"$(JAVA_HOME)\include" -I"$(JAVA_HOME)\include\win32" -I"$(JNI_DIR)" -c $< -o $@
clean : $(JNI_DIR)/java_exercises7_2_1_HelloJNI.h :
rm HelloJNI.h HelloJNI.o hello.dll java_exercises7_2_1_HelloJNI.dll java_exercises7_2_1_HelloJNI.h java_exercises7_2_1_HelloJNI.o javac -h $(JNI_DIR) -d $(CLASS_PATH) $(SRC_DIR)/java_exercises7_2_1/HelloJNI.java
\ No newline at end of file
clean :
rm -Rf $(JNI_DIR)/*.h $(JNI_DIR)/*.o $(JNI_DIR)/*.so $(JNI_DIR)/*.dll $(CLASS_PATH)/*
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment