使用JNA将多个.dll库注册到单个java类中 [英] Registering multiple .dll libraries into a single java class using JNA

查看:370
本文介绍了使用JNA将多个.dll库注册到单个java类中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先在一些上下文中,彻底解释我已经尝试的方法:



我正在一个基于Java的编程平台上,访问定制的java函数与其他几个扩展。在这个建模平台的源代码中,有一个类CVODE,它允许访问本机库cvode来导入C ++库的功能



所以我只能猜测调用Native.register()两次的错误结果。导致第二个库没有加载或错误的方式。我会很欣赏一下我在做错什么的一些洞察力,或者如何更好地了解出了什么问题。

解决方案

据我所知,您只能加载一个dll每个类,即将类分为两个,每个提供特定dll提供的方法。



另请参见: https://stackoverflow.com/a/32630857/1274747


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. 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.

//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.

Adding the first library to my java path obviously resulted in

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. Resulting in an error indicating that not all methods are present in the library 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. 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:

So I can only guess the error results from calling the Native.register() twice. 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, i.e. split the classes into two, each providing the methods the particular dll provides.

See also here: https://stackoverflow.com/a/32630857/1274747

这篇关于使用JNA将多个.dll库注册到单个java类中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆