Search code examples
javajava-native-interfacestatic-libraries

Statically linked libraries and JNI?


I am planning an application which will make use of an existing 3rd party SDK supplying a collection of statically linked (.lib) C++ libraries. I would like to write my own application in Java, so I played around a bit with loading the existing SDK libraries into the VM.

However , as far as I can tell, the JVM seems to be able to use only dynamically linked libraries (.dll).

Is this true? If so is there a possible work around - like compiling a .dll of my own which links to the static libraries? I've a fair amount of experience with Java but am new to both JNI and C/C++ so any response or push in the right direction would be much appreciated,

Cheers!


Solution

  • You are correct: the JVM can load dlls (you normally have some startup code in the Java source code that contains native functions to load them). It cannot load libs.

    So you will need to create a dll that statically links to the libs.

    The normal way to do this is to run the program javah which will generate the stubs for the dll functions that you need to implement.