Created
May 6, 2014 16:36
-
-
Save dhilst/eb78517ca3ed9db78f46 to your computer and use it in GitHub Desktop.
JNI Hello World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HelloWorld.h" | |
JNIEXPORT void JNICALL Java_HelloWorld_sayHello | |
(JNIEnv *env, jclass class) | |
{ | |
puts("Hello from C world"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloWorld { | |
static { | |
System.loadLibrary("HelloWorld"); | |
} | |
public static native void sayHello(); | |
public static void main(String[] args) { | |
sayHello(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JAVA_HOME = /opt/java6 | |
.PHONY: all clean run | |
all: HelloWorld.class libHelloWorld.so | |
HelloWorld.class: HelloWorld.java | |
javac $< | |
HelloWorld.h: HelloWorld.class | |
javah HelloWorld | |
HelloWorld.c: HelloWorld.h | |
libHelloWorld.so: HelloWorld.c | |
gcc -fPIC -shared -Wall -o $@ $< -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux | |
run: | |
LD_LIBRARY_PATH=. java HelloWorld | |
clean: | |
rm -rf HelloWorld.class HelloWorld.h libHelloWorld.so |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment