Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

jni

simple demo for jni

How to

From src/main/java execute

javac davide/jni/HalloFromC.java

Then execute

javah -jni davide.jni.HalloFromC

which generates the header file davide_jni_HalloFromC.h.

In a C file, implement the methods automatically generated:

JNIEXPORT jint JNICALL Java_davide_jni_HalloFromC_sum
  (JNIEnv * env, jobject obj, jint a, jint b) {
  return a+b;
  }

Using the Makefile, compile the C file into a shared library.

Export the environment variable:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.

Then execute:

java davide.jni.HalloFromC

About

simple demo for jni

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages