Swig a DLL into Java

前端 未结 1 664
太阳男子
太阳男子 2021-01-15 01:37

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 hav

1条回答
  •  执笔经年
    2021-01-15 02:21

    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.

    0 讨论(0)
提交回复
热议问题