Problem using OpenCascade from Java with JNI: Can't find dependent libraries

Hi,

First of all, here is the list of that I'm using to develop in Java:

- OS=Windows 10 64 bits
- Using Eclipse to develop in Java (Eclipse "Kepler")
- Using Java Runtime JRE 1.8.0_91 64 bits

And this is what my coworker is using to develop in C

- OS=Windows 10 64 bits
- Microsoft Visual Studio 2015 
- OpenCASCADE7.0.0-vc12-64

Well, my coworker has developed some code in C and using OpenCascade. I'm trying to use JNI to use what he developed. I already know how to use JNI, since I run a few basic examples (how to create de ".h" file using "javah", how to include that file when compiling the C code in Visual Studio, how the Java methods must match some methods in the ".h" file which must match some funcions in the C code, etc). When my coworker gave me an initial simple code in C, I was able to call one of his simple C methods from JNI, so I think I already know the basics about how to use JNI.

The problem started when he started using OpenCascade in his C code. This is what I get, and it happens with the System.loadLibrary(NEInterface3D) method:

java.lang.UnsatisfiedLinkError: Z:\Brian\NestingBusiness\Archivos\NEInterface3D.dll: Can't find dependent libraries
                java.lang.ClassLoader$NativeLibrary.load(Native Method)
                java.lang.ClassLoader.loadLibrary0(Unknown Source)
                java.lang.ClassLoader.loadLibrary(Unknown Source)
                java.lang.Runtime.loadLibrary0(Unknown Source)
                java.lang.System.loadLibrary(Unknown Source)
                NEInterface3D.JNIStep.<clinit>(JNIStep.java:27)

The problem is NOT that JNI can not find the file "NEInterface3D.dll" which is the main DLL, but that some libraries can not be found. What libraries exactly? I don't know.
I already used "Dependency Walker" (http://www.dependencywalker.com) and I see a tonelade of files that seems to be missing, most of them in the form "API-MS-WIN-**************" which, according to what I read somewhere, is a false alarm. That is very misleading.

Here are my questions:

- How can I know exactly what files are missing when I get the Java exception java.lang.UnsatisfiedLinkError? 
- How can I know exactly what are ALL the libraries what are "missing"? Are those DLLs, or maybe something else?
- Where do I get all those missing files from?
- Where do I have to place all those missing files, how do I tell Java/JNI where they are? I'm already using this to tell Java/JNI where is the main ".dll" file and it works: -Djava.library.path="(Windows path)"

I'm very seasoned with Java, but I'm not a C developer. I'm in charge of the integration and that includes using Visual Studio to generate the ".dll" file, so I had to learn how to do that. I think I'm doing it correctly, I'm including all the files that are required according to my coworker (the C developer) so the ".dll" generation seems to have been successful. But the problem takes place with the System.loadLibrary() method, as I described.

Thanks in advance,

Brian

 

Forum supervisor's picture

Hello Brian,

We have sent to you a personal message about our Advanced Java Wrapper tool - please, check your mailbox.

Best regards,

Forum supervisor

Luis Diago's picture

 Hi, I have the same problem. 

Petr Matousek's picture

Hello Brian,

I am in a similar situation - I have to call the OCCT libs from Java. Here are my answers to your questions:

How can I know exactly what files are missing when I get the Java exception java.lang.UnsatisfiedLinkError?

  • use Dependency Walker
  • ignore the "API-MS-WIN-**************" focus on the rest
  • compare the .dlls reported as missing with the contents of the OCCT_ROOT/opencascade-7.0.0/win64/bin directory
  • maybe your NEInterface3D.dll is linked with some other libraries, not only OCCT? at least C/C++ runtime? if so, look into these libs directories too
  • if Dependecy Walker does not help you try to use https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx
  • watch all the I/O activity on local disk and you will see what .dlls the system is trying to load and from which locations

How can I know exactly what are ALL the libraries what are "missing"? Are those DLLs, or maybe something else?

  • in my case the exception java.lang.UnsatisfiedLinkError signaled just missing dlls
  • Process Monitor will tell you the truth

Where do I get all those missing files from?

  • OCCT_ROOT/opencascade-7.0.0/win64/bin directory
  • in case your NEInterface3D.dll is linked with other libraries you have to look into these libs directories too

Where do I have to place all those missing files, how do I tell Java/JNI where they are? I'm already using this to tell Java/JNI where is the main ".dll" file and it works: -Djava.library.path="(Windows path)"

  • -Djava.library.path will just tell the JVM where to look for the NEInterface3D.dll
  • if your NEInterface3D.dll is linked with other .dlls they are loaded by the OS dynamic linker, so I guess PATH environment variable will be used
  • in my case I put all the dependency .dlls into the same directory as the main .dll resides (in your case NEInterface3D.dll)
  • watch the Process Monitor log - it will tell you where the system is trying to load dependent .dlls from

I hope, it will help. Good luck! Petr