Skip to content

Instantly share code, notes, and snippets.

@dhilst
Last active September 27, 2016 02:39
Show Gist options
  • Select an option

  • Save dhilst/531e2e967374d585cbd17f12c1684775 to your computer and use it in GitHub Desktop.

Select an option

Save dhilst/531e2e967374d585cbd17f12c1684775 to your computer and use it in GitHub Desktop.
public class HelloJNIWorld {
static {
System.loadLibrary("hellonativeworld");
}
static native void helloWorld();
public static void main(String[] args) {
helloWorld();
}
}
#include "HelloJNIWorld.h"
JNIEXPORT void JNICALL Java_HelloJNIWorld_helloWorld
(JNIEnv *env, jclass cls)
{
puts("Hello native world");
}
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