Is it possible to build a HelloWorld.lib and load it to a Java application using JNI? Or it just works with shared libraries?
I couldn't find a clear answer on the JNI documentation, there's no reference to "static library".
Static libraries are either merged with other static libraries and object files during building/linking to form a single executable or loaded at run-time into the address space of their corresponding executable at a static memory offset determined at compile-time/link-time.
I was following a tutorial video on compilers on YouTube, when I came across the fact that the C Programming Language is faster because it allows both static linking and dynamic linking, but Java allows only dynamic linking and that is why C is much faster than Java.
Static Linking and Static Libraries is the result of the linker making copy of all used library functions to the executable file. Static Linking creates larger binary files, and need more space on disk and main memory.
JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).
It needs to be a dynamic library. Fortunately, you can build a dynamic library from a static one.
Java 8 supports statically linked native libraries http://openjdk.java.net/jeps/178
To load a library at runtime it must be a dll (windows). If you have a static library (lib) and you have to use it via JNI you have to create a wrapper dll
You would have to link it to the JVM, and you don't have a way to do that. That's why JNI is defined with shared libraries, not static ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With