Last active
September 27, 2016 02:39
-
-
Save dhilst/531e2e967374d585cbd17f12c1684775 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class HelloJNIWorld { | |
| static { | |
| System.loadLibrary("hellonativeworld"); | |
| } | |
| static native void helloWorld(); | |
| public static void main(String[] args) { | |
| helloWorld(); | |
| } | |
| } |
This file contains hidden or 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 "HelloJNIWorld.h" | |
| JNIEXPORT void JNICALL Java_HelloJNIWorld_helloWorld | |
| (JNIEnv *env, jclass cls) | |
| { | |
| puts("Hello native world"); | |
| } |
This file contains hidden or 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 ?= /etc/alternatives/java_sdk | |
| CFLAGS += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux | |
| all: libhellonativeworld.so | |
| libhellonativeworld.so: libhellonativeworld.c HelloJNIWorld.h | |
| HelloJNIWorld.h: HelloJNIWorld.class | |
| HelloJNIWorld.class: HelloJNIWorld.java | |
| %.so: %.c | |
| $(CC) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o $@ $< | |
| %.h: %.class | |
| javah -cp . $(<:.class=) | |
| %.class: %.java | |
| javac -cp . $< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment