tags:

views:

1192

answers:

4

I am trying to load a dll in java using the following code System.loadLibrary("mydll");

The project is placed in D:\development\project\ and i have placed the dll on D:. I then gave following VM argument in eclipse configuration -Djava.library.path=D:/

But when i run i get UnsatisifiedLinkerError. After googling a bit, I used System.load("D:\mydll.dll");

but again getting the same problem, could someone can help?

A: 

Where you specify the DLL filename in the library path, omit that. Additionally, your System.loadLibrary call should just be 'mydll'. I can tell you (from experience) that if you put the DLL in the root of your project in Eclipse (i.e., D:\Eclipse Workspace\Proj), it should work. Any further linker errors could be from dependency problems with finding other DLLs. The exception is the same. Use something like Dependency Walker (http://www.dependencywalker.com/) to see if your DLL relies on anything else not on the system library path.

Edit: UnsatisfiedLinkError: Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native -- it seems like you are using a JNI function which does not exist.

Chris Dennett
A: 

Using System.loadLibrary("mydll") works fine, you can also use that one. If you used javah and you think with your DLL everything is fine, there are two possibilies:

  1. The JVM does not find your DLL: In this case, your java library path is not correct (which I doubt) and you should probably set it to . and place your DLL in the current working dir.
  2. The JVM does not find a DLL your DLL depends on: If you have any dependent libraries in your DLL, they are NOT searched by the JVM, but by Windows itself. And Windows does not know the java.library.path, so it will look in the system PATH variable for those. If you have the possibility, you can set the system PATH variable to the location of your DLLs before starting the JVM and everything will be fine. Or you can load all your DLLs using the JVM like this

    System.loadLibrary("dll_1");
    System.loadLibrary("dll_2");
    System.loadLibrary("dll_3");

    where dll_3.dll depends on dll_2.dll, which depends on dll_1.dll.

Hope that helps.

David Sauter
A: 

In the Java file that has the interfaces that you passed through javah Make sure your loadLibrary is defined as a static.

  static {
    System.loadLibrary("mydll");
  }

Make sure your path has where to find the dll

Romain Hippeau
A: 

@alee- You can just copy and the paste the dll files in system32 folder of your windows and try to call the library through the System.loadLibrary("mydll")... i guess it may work...

navinbecse