views:

56

answers:

1

Hello,

I wrote a Java class which accesses a method in the C dll through Jni. But i am getting the following error in windows.

java.lang.UnsatisfiedLinkError: Server.getNetworkDiagram(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

Guess it is able to load the library.

Also i am building the .dll (for windows) and .so (for linux) from a set of common C files This works with .so file and i do not get any error.

Could you please help me out ? How do i debug here ?

Thanks, Sudarshan

Not sure whether it is misspelt because it works in linux. Below are the header file and the Java file.

========

JNI File

/* DO NOT EDIT THIS FILE - it is machine generated */

include

/* Header for class Server */

ifndef _Included_Server

define _Included_Server

ifdef __cplusplus

extern "C" {

endif

undef Server_GETNETWORK

define Server_GETNETWORK 1L

undef Server_SETLEVEL

define Server_SETLEVEL 2L

/* * Class: Server * Method: getNetworkDiagram * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_Server_getNetworkDiagram (JNIEnv *, jobject, jstring, jstring, jstring);

/* * Class: Server * Method: setLevelQuery * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IILjava/lang/String;)Z */ JNIEXPORT jboolean JNICALL Java_Server_setLevelQuery (JNIEnv *, jobject, jstring, jstring, jstring, jint, jint, jstring);

ifdef __cplusplus

}

endif

endif

=========

Java File

public class Server { public native String getNetworkDiagram(String domain, String dest, String secret);

public void test()
{
    String domain = "domain1";
    String host = "2.2.2.30";
    String secret = "test";

    System.loadLibrary("libewapi");     
    String result = this.getNetworkDiagram(domain, host, secret);           
}

public static void main(String argv[]) throws Exception
{                   
    Server server = new Server();
    server.test();
}

}

A: 

there's a chance your referencing the library by a diferent name, maybe misspelled? or the both function names on the jni.h file or java class do not correspond.

could you post the function declaration in the jni.h file and the java native method implementation?

jgemedina
Could not paste the whole file here. I have edited in the main post. thanks for the help
Everything seems to be ok, you could be getting that exception for two causes:1.- the DLL file cannot be found? is it in the application root?2.- Including the C header file in the C code file itself, you need it for the methods definition and the C keyword definition also.Sometimes the compiler might change the method name (symbol) you could dissassmble the library to see the symbol table, see if there's any change.What enviroment are you using to build the library on windows?
jgemedina
Yeah. I am using windows 7 and i have placed the dll in C:\Windows\SysWOW64 directory Guess it is able to locate and load the dll.I tried disassembling the dll using the dependency walker. The function names were the same.Only problem i saw in it was it said there were two dll's missing. They are GPSVC.dll and IESHIMS.dllWe are using a cross compiler to build the Dll from a linux machine.It is a i386-ming compiler.
Give it a try and put it in C:\Windows\System32, perhaps those missing dlls are not located on syswow64.another option is to build the library using a windows env, like the borland compiler
jgemedina
Placed the file in the system32 directory and it did not work. Not sure what is wrong here. As you say, probably i will try to build it in windows env. I have a small doubt. The machine i am using is a 64 bit machine but the library i loaded was a 32 bit. Will it be a problem ? I did not get any error during the system call loadLibrary. thanks for the help
Perhaps building the library on a windows environment would do the trick, as for the 64bits environment, 32bit libraries should without problem be loaded on a 32bit application address space, otherwise you would get some exception from the java ClassLoader, the OS cannot load a 32bit library into a 64 bit reserved address space.as you say, System.loadLibrary() does the work perfectly, what i think is that the cross compiler is producing something somewhat different from what you need, try a windows tool to build it.as for the help, you're welcome! :)
jgemedina