简体   繁体   English

使用JNA将多个.dll库注册到单个Java类中

[英]Registering multiple .dll libraries into a single java class using JNA

First of all some context, to thoroughly explain the methods I've already tried: 首先,要全面解释我已经尝试过的方法:

I'm working in a java-based programming platform on windows which provides access to custom java functions with several other extensions. 我正在Windows上一个基于Java的编程平台上工作,该平台可访问具有其他几个扩展名的自定义Java函数。 Within the source code of this modelling platform, there is a class "CVODE" which grants access to native library "cvode" to import the functionality of a C++ library CVODE . 在此建模平台的源代码中,存在一个类“ CVODE”,该类授予对本机库“ cvode”的访问权,以导入C ++库CVODE的功能

//imports
public class CVODE {

    static {
        Native.register("cvode");
    }
    public static native int ... //methods
}

I created shared libraries from the CVODE library, which resulted in 2 files: sundials_cvode.dll and sundials_nvecserial.dll. 我从CVODE库创建了共享库,生成了2个文件:sundials_cvode.dll和sundials_nvecserial.dll。

Adding the first library to my java path obviously resulted in 将第一个库添加到我的java路径显然导致

Unexpected Exception UnsatisfiedLinkError: Unable to load library 'cvode': The specified module could not be found.

as the names were not compatible. 因为名称不兼容。 Therefore I changed the name of sundials_cvode.dll to cvode.dll and retried. 因此,我将sundials_cvode.dll的名称更改为cvode.dll并重试。 Resulting in an error indicating that not all methods are present in the library sundials_cvode.dll: 导致错误,表明并非所有方法都存在于库sundials_cvode.dll中:

Unexpected Exception UnsatisfiedLinkError: Error looking up function 'N_VDestroy_Serial': The specified procedure could not be found.

This convinces me that the library is being found and loaded correctly , but not all methods are available. 这使我确信可以正确找到并加载该库 ,但并非所有方法都可用。 Examining the dll's in question led me to the conclusion that the CVODE class requires functions from both the sundials_cvode.dll and sundials_nvecserial.dll libraries. 检查该dll会得出一个结论,即CVODE类需要sundials_cvode.dll和sundials_nvecserial.dll库中的函数。 Therefore I tried changing the platform source-code to 因此,我尝试将平台源代码更改为

public class CVODE {

    static {
        Native.register("sundials_cvode");
        Native.register("sundials_nvecserial");
    }
    public static native int ... //methods
}

which still results in 仍然导致

Unexpected Exception UnsatisfiedLinkError: Error looking up function 'N_VNew_Serial': The specified procedure could not be found.

I have confirmed this method is present in both the class file and in the dll: 我已经确认在类文件和dll中都存在此方法: 在此处输入图片说明

So I can only guess the error results from calling the Native.register() twice. 因此,我只能猜测两次调用Native.register()的错误结果。 resulting in the 2nd library not being loaded or an error down the way. 导致第二个库未加载或错误。 I'd appreciate some insight in what I'm doing wrong or how I can gain a better overview of what's going wrong. 我希望对自己做错了什么或如何更好地了解发生的问题有一些见解。

As far as I know, you can only load one dll per class, ie split the classes into two, each providing the methods the particular dll provides. 据我所知,每个类只能加载一个dll,即将这些类拆分为两个,每个类都提供特定dll提供的方法。

See also here: https://stackoverflow.com/a/32630857/1274747 另请参阅此处: https : //stackoverflow.com/a/32630857/1274747

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM