Skip to content

smasher164/staticjni

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Statically-linked Native Image w/ JNI

Cross-platform build instructions.

  1. The header file HelloWorld.h was generated by running javac -h . HelloWorld.java. Since this is checked into the repo, it doesn't need to be run again.

    The dependency org.graalvm.nativeimage/svm has been added to the project. In this repo's case, the jar was unzipped into the classpath. If you're using a package manager or build system, follow their respective instructions to add a dependency.

  2. javac -cp . HelloWorld.java NativeFeature.java

  3. jar cfm HelloWorld.jar manifest.txt HelloWorld.class NativeFeature.class

    • Linux: cc -c -I "$JAVA_HOME/include" -I "$JAVA_HOME/include/linux" -o native.o Native.c
    • MacOS: cc -c -I "$JAVA_HOME/include" -I "$JAVA_HOME/include/darwin" -o native.o Native.c
    • Windows (msvc): cl /I "%JAVA_HOME%\include" /I "%JAVA_HOME%\include\win32" /c Native.c
    • Linux and MacOS: ar rcs libNative.a native.o
    • Windows (msvc): lib Native.obj
  4. native-image -jar HelloWorld.jar -H:CLibraryPath=.

About

Statically link JNI library with native-image

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages