将 DLL 注入 Java [英] Swig a DLL into Java
问题描述
有谁知道是否可以使用 Swig 为带有捆绑的 C 头文件的 DLL 生成 Java 接口?有很多教程描述了如果您有源 (http://www.swig.org/Doc1.3/Java.html).
Does anybody know whether it's possible to use Swig to generate a Java interface for a DLL with bundled C headers? There're many tutorials describing what to do if you have the source (http://www.swig.org/Doc1.3/Java.html).
推荐答案
即使您只有头文件和 DLL,您链接到的教程中的所有信息仍然相关.您所需要的只是标题和链接到它的库.
All of the information in the tutorial you linked to is still relevant even if you only have header files and a DLL. All you need is the headers and a library to link against it.
那么你有两个选择.您可以让您的构建过程将 SWIG 生成的代码与现有的 DLL 链接起来,或者您可以使用以下内容:
You have two choices then. Either you can make your build process link the SWIG generated code with the existing DLL, or you can use something like this:
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("mylibrarythatIonlyhaveaDLL");
System.loadLibrary("swigmodule");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}
在您的接口文件中强制在 SWIG 生成的接口之前加载 DLL.
in your interface file to force the DLL to be loaded before the SWIG generated interface.
这篇关于将 DLL 注入 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!