4

我必须调用一个 dll 方法并且我没有来自 dll 的源代码,我正在阅读有关 JNI 并了解您应该具有在代码 (.h) 中输入 JNI 库的源代码。

我的第二次拍摄是 JNA,但我遇到了同样的错误,尽管您不必更改 DLL 中的任何内容。

我创建了两个类来测试:

界面:

package icom;

import com.sun.jna.Library;

public interface IConectorT extends Library {
    int StartConector(byte[] conectorStatus, String icomPath);
}

DLL方法调用:

package icom;

import com.sun.jna.Native;

public class ConectorTJna {

    public static void main(String args[]) {

        IConectorT lib = (IConectorT) Native.loadLibrary("ConectorT", IConectorT.class);
        int teste = lib.StartConector(null, "C:\\ICOM");
        System.out.println("RESULT: " + teste);
    }
}

当我调用该lib.StartConector方法时,我得到了这个:

线程“主”java.lang.UnsatisfiedLinkError 中的异常:查找函数“StartConector”时出错:找不到指定的过程。在 com.sun.jna.Function.(Function.java:179) 在 com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:350) 在 com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:330)在 com.sun.jna.Library$Handler.invoke(Library.java:203) 在 $Proxy0.StartConector(Unknown Source) 在 icom.ConectorTJna.main(ConectorTJna.java:10)

4

1 回答 1

1

Did you specify path to the library, e.g. using system property?

Here are the details from "Getting Started with JNA" guide:

Make your target library available to your Java program. There are two ways to do this:

  1. The preferred method is to set the jna.library.path system property to the path to your target library. This property is similar to java.library.path, but only applies to libraries loaded by JNA.

  2. Change the appropriate library access environment variable before launching the VM. This is PATH on Windows, LD_LIBRARY_PATH on Linux, and DYLD_LIBRARY_PATH on OSX.

Taken from: https://github.com/twall/jna/blob/master/www/GettingStarted.md

于 2012-08-13T21:29:56.807 回答