Thread: Using SWIG to wrap a C++ class for use in Java

  1. #1
    Registered User
    Join Date
    Nov 2009

    Using SWIG to wrap a C++ class for use in Java


    Has anyone here ever used SWIG before to get your C++ library to java?

    I have a method that is declared like so

    unsigned char** classify()

    and I want to be able to use this method in java - preferrably returning to a byte array.

    What do I need to do to my swig interface file so that it will let me have this type of return? So far, when I try to use the classify method in java, like:

    byte[][] = p.classify()

    It tells me that the return type of classify is void

  2. #2
    Registered User
    Join Date
    Nov 2009
    more info:

    I have a c++ function declared as

    unsigned char** classify

    I am using the following inteface file in SWIG
    %module PWrap
    %include "std_string.i"
    %include "arrays_java.i"
    %apply byte[][] {unsigned char**};
    #include "Classifier.h"
    %include "Classifier.h"
    which generated some files, including a SWIGTYPE_p_p_unsigned_char object

    Now, heres where I try to use this C++ function in java:

    SWIGTYPE_p_p_unsigned_char data = pc.classify();//this works, but i cant do anything with the data object execept pass it to other C++ functions expecting unsigned char**
    byte[][] data2 =pc.classify();//this does not work

    So I really just need to know how to do the mapping to get that SWIGTYPE out of there, and be able to use btye correctly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get class bytes? (Java)
    By Sebastiani in forum General Discussions
    Replies: 3
    Last Post: 07-11-2009, 07:21 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. which design is better to wrap another class instance
    By George2 in forum C++ Programming
    Replies: 7
    Last Post: 04-13-2008, 12:27 AM
  4. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  5. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM

Tags for this Thread