3

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!

user3881521
  • 95
  • 1
  • 7

1 Answers1

3

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.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
  • +1 - One thing to be aware of, frequently a .lib is just a link library (stubs) to a .dll. So you end up creating a dll to a link library to another dll, but this is mostly unavoidable unless you have the source of the original lib with which to add Java compatible entry points. Just check that your .lib is indeed fully contained, or make sure you also get its dependencies. Usually the size of the file gives it away (static .lib will be comparable, link lib will be small). – codenheim Aug 11 '14 at 16:01
  • Wow that was quick! Thanks for the responses, very helpful. – user3881521 Aug 11 '14 at 19:17