Registering multiple .dll libraries into a single

2019-08-09 10:11发布

问题:

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.

回答1:

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