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

This is a discussion on Using SWIG to wrap a C++ class for use in Java within the C++ Programming forums, part of the General Programming Boards category; Hello, Has anyone here ever used SWIG before to get your C++ library to java? I have a method that ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    24

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

    Hello,

    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
    Posts
    24
    more info:

    I have a c++ function declared as

    unsigned char** classify

    I am using the following inteface file in SWIG
    Code:
    %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:

    Code:
    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, 08: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, 09: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, 01:27 AM
  4. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 02: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21