Swig a DLL into Java

半腔热情 提交于 2019-12-19 10:28:59

问题


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


回答1:


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.

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);
    }
  }
%}

in your interface file to force the DLL to be loaded before the SWIG generated interface.



来源:https://stackoverflow.com/questions/6193120/swig-a-dll-into-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!