SWIG Importing generated class from a different module and package into the current class

梦想的初衷 提交于 2019-12-04 09:58:24

Got the same problem and found answer, so posting it for community.

You need to make 3 changes.

  1. Add import statements to generated proxy class (Bar.java):

    // Bar.i
    %pragma(java) jniclassimports=%{
    import com.me.t.foo.Foo;
    %}
    
  2. Add import statements to generated JNI wrapper class (BarModJNI.java):

    // Bar.i
    %typemap(javaimports) Bar %{
    import com.me.t.foo.Foo;
    %}
    
  3. Tell SWIG to make Foo.getCPtr a public member variable because Bar class will want to access it:

    // Foo.i
    SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
    SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
    

Reference:

Just a couple of comments on the answer provided by Zbigniew. I have faced the same problem described in this post. I would like to clarify two points.

Firstly, it seems to me that step 1 is for adding the import in JNI wrapper class (whateverJNI.java) while step 2 is for adding import to the specific class.

Secondly, step 2 is not working for me, instead of %typemap(javaimports) <class> I had to use %typemap(javaimports) SWIGTYPE. Bad thing is it adds the imports to all the generated java classes and not only to the desired one.

Finally, I am still having the problem that SWIG does not recognize the imported class when wrapping the specific type and it still uses SWIGTYPE_<type> instead of directly <type>

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