Trying to use DLL from Java (JNA). Unable to load library exception

后端 未结 5 2135
囚心锁ツ
囚心锁ツ 2020-11-30 14:13

I have NetBeans project from tutorial which causes exception:

Exception in thread \"main\" java.lang.UnsatisfiedLinkError: Unable to load library \'s

5条回答
  •  温柔的废话
    2020-11-30 14:18

    Three possible reasons for this issue, if the dll file is not broken:

    1. 32 bit 64 bit Compatibility. 32bit dll can only be running on a 32bit jdk or jre. By using Cygwin command file we can tell if a dll is 32bit or 64bit.

    2. the dll is not lacated in the right path, so java cannot locate it. Generally speaking we can use some absolut path other than System32 to ensure that the path is right.

    3. the dll that we are loading is requires other dlls.

    How can we handle the 3rd possibility:

    1. using JNI's System.loadLibrary() mthod can give me more hint, compared with JNA. It may says something like: Exception in thread "main" java.lang.UnsatisfiedLinkError: MyLibrary.dll: Can't find dependent libraries. It means some libraries MyLibrary.dll depends is missing. By using dependency walker we can tell what dlls are needed.

    2. By loading these dlls before the dll that we want to load, we can solve this issue.

提交回复
热议问题