[Swig-user] (Noob) Help with int64_t and java

107 views
Skip to first unread message

Robert Baruch

unread,
Mar 15, 2012, 1:02:06 PM3/15/12
to swig...@lists.sourceforge.net
So I'm trying to make some elementary Java bindings on OSX for OpenCV (http://opencv.willowgarage.com/wiki/). Having never used SWIG before, I'm just trying to access some of the global functions in core. Here are the relevant sections from the header files:

==== opencv2/core/core.hpp ====

...
#include "opencv2/core/types_c.h"
...
namespace cv {
...
CV_EXPORTS_W int64 getTickCount();
...
}

===========================

==== opencv2/core/types_c.h ====

...
#if !defined _MSC_VER && !defined __BORLANDC__
  #include <stdint.h>
#endif
...
#define CV_EXPORTS_W CV_EXPORTS
...
#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS
    #define CV_EXPORTS __declspec(dllexport)
#else
    #define CV_EXPORTS
#endif
...
#if defined _MSC_VER || defined __BORLANDC__
typedef __int64 int64;
typedef unsigned __int64 uint64;
#define CV_BIG_INT(n)   n##I64
#define CV_BIG_UINT(n)  n##UI64
#else
typedef int64_t int64;
typedef uint64_t uint64;
#define CV_BIG_INT(n)   n##LL
#define CV_BIG_UINT(n)  n##ULL
#endif

============================



So, because I'm not on Windows, CV_EXPORTS_W should be nothing, and int64 should be int64_t, which is defined in stdint.h.


Here's my interface file:

==== opencv.i ====

%module OpencvCoreGlobal
%{
#include "opencv2/core/core.hpp"
%}
namespace cv {
extern int64 getTickCount();
}

================



The problem that I'm having is that SWIG appears to treat int64 as an opaque type rather than a Java long. What am I doing wrong?



===== Command line =====

$ swig -verbose -I/usr/local/include -java -c++ opencv.i
LangSubDir: java
Search paths:
   ./
   /usr/local/include/
   ./swig_lib/java/
   /usr/share/swig/1.3.31/java/
   ./swig_lib/
   /usr/share/swig/1.3.31/
Preprocessing...
Starting language-specific parse...
Processing types...
C++ analysis...
Generating wrappers...
$

================

======= OpencvCoreGlobal.java =======

public class OpencvCoreGlobal {
  public static SWIGTYPE_p_int64 getTickCount() {
    return new SWIGTYPE_p_int64(OpencvCoreGlobalJNI.getTickCount(), true);
  }

}

==================================

====== OpencvCoreGlobalJNI.java ======

class OpencvCoreGlobalJNI {
  public final static native long getTickCount();
}

==================================

====== SWIGTYPE_p_int64.java ========

public class SWIGTYPE_p_int64 {
  private long swigCPtr;

  protected SWIGTYPE_p_int64(long cPtr, boolean futureUse) {
    swigCPtr = cPtr;
  }

  protected SWIGTYPE_p_int64() {
    swigCPtr = 0;
  }

  protected static long getCPtr(SWIGTYPE_p_int64 obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }
}

=================================

Thanks,

--Rob



William S Fulton

unread,
Mar 15, 2012, 5:28:35 PM3/15/12
to Robert Baruch, swig...@lists.sourceforge.net

Try %include stdint.i.

William

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Swig-user mailing list
Swig...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Mathieu Malaterre

unread,
Mar 16, 2012, 4:01:21 AM3/16/12
to William S Fulton, swig...@lists.sourceforge.net
On Thu, Mar 15, 2012 at 10:28 PM, William S Fulton
<w...@fultondesigns.co.uk> wrote:

As william said. One more note, the following is simpy wrong:

>> #if !defined _MSC_VER && !defined __BORLANDC__

VS2010 comes with a stdint.h header file

2cts
--
Mathieu

Reply all
Reply to author
Forward
0 new messages