0

I'm new to dependency walker and I'm trying to determine if my dll contains a C function that I'm trying to call from Java via JNI. When I select the dll that should contain the C function in Dependency Walker, I get the import and export functions. The import list has the setLogLevel function but the entry point is not bound (as is for all functions in this list) and shows up with a green box with a c. The export list as has a setLogLevel function and has 0x00003C25 as the entry point. When I try to call the setLogLevel from JAVA/JNI I get the below. I'm not sure if the import/exports are right, can anyone confirm?

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.test.jni.SampleJNI.setLogLevel(I)V
            at com.test.jni.SampleJNI.setLogLevel(Native Method)
            at com.test.jni.Sample.setLogLevel(Unknown Source)
            at com.test.jni.Example.setLogLevel(Unknown Source)
            at com.test.jni.Example.main(Unknown Source) 
c12
  • 9,557
  • 48
  • 157
  • 253

2 Answers2

0

Your C function is named incorrectly. The name must be prefixed with Java and contain the package and class name. In your case, it should be Java_com_test_jni_SampleJNI_setLogLevel.

kichik
  • 33,220
  • 7
  • 94
  • 114
  • the JNI dll (SampleJNI.dll) has it named Java_com_test_jni_SampleJNI_setLogLevel@12, the imports and exports above are from the real C function's dll which is a dependency of SampleJNI.dll. – c12 Jan 05 '12 at 00:31
  • The error suggests the problem is with the JNI DLL. But that's easy to verify. Use `regsvr32` on your JNI DLL and see what it complains about. If it complains about not finding `DllRegisterServer`, the import from the C functions DLL is working fine. – kichik Jan 05 '12 at 00:59
  • the command yielded "c:\temp\SampleJNI.dll was loaded, but the DllRegisterServer entry point was not found. The file can not be registered" so that means the dll is valid? – c12 Jan 05 '12 at 01:08
  • Yep. The problem is probably the name. Did you use `JNIEXPORT`? – kichik Jan 05 '12 at 01:28
  • The dll name or the name of the java function that is mapped to the c function? The SampleJNI.java has a public final static native void setLogLevel(int jarg1); The dll is name properly as the System.loadLibrary("SampleJni") doesn't throw an exception – c12 Jan 05 '12 at 01:41
  • I use SWIG to generate the JNI files and all works fine on Linux so I'm making the assumption that the naming is fine. – c12 Jan 05 '12 at 02:10
0

I had omitted the java directories that have the jdk's jni.h and jni_md.h header files from the CFLAGS (compile) include in the Makefile. Once I added those to the Makefile I was able to communicate from java to c via JNI method calls.

c12
  • 9,557
  • 48
  • 157
  • 253