1. camlspotter
  2. ojacare

Commits

camlspotter  committed 7959508

learned how to call C func from Java

  • Participants
  • Parent commits 84a2bae
  • Branches android

Comments (0)

Files changed (3)

File camljava-0.3/test_simple_call_from_java/Makefile

View file
+all: Test.class libTestC.so
+	LD_LIBRARY_PATH=. java Test
+
+Test.class: Test.java
+	javac Test.java
+
+Test.h: Test.class
+	javah -jni Test
+
+JAVA=/usr/lib/jvm/java-6-openjdk-i386/
+
+TestC.o: Test.h TestC.c
+	gcc -c -I $(JAVA)/include TestC.c
+
+libTestC.so: TestC.o
+	gcc -shared TestC.o -o $@
+
+clean:
+	rm -f *.o *.so *.class Test.h
+

File camljava-0.3/test_simple_call_from_java/Test.java

View file
+public class Test {
+    public static void main (String[] args) {
+	System.loadLibrary("TestC");
+	Test i = new Test();
+	i.putchar(64);
+	System.out.println("Hello world !!");
+    }
+
+    private native int putchar(int c);
+}

File camljava-0.3/test_simple_call_from_java/TestC.c

View file
+#include "Test.h"
+
+JNIEXPORT jint JNICALL Java_Test_putchar(JNIEnv* env, jobject obj, jint c)
+{
+    return putchar(c);
+}