Basic SWIG C++ use for Java
- by duckworthd
I've programmed a couple years in both C++ and Java, but I've finally come to a point where I need to bring a little unification between the two -- ideally, using SWIG. I've written a tiny and fairly pointless little class called Example:
#include <stdio.h>
class Example {
public:
Example();
~Example();
int test();
};
#include "example.h"
Example::Example()
{
printf("Example constructor called\n");
}
Example::~Example()
{
printf("Example destructor called\n");
}
int Example::test()
{
printf("Holy sh*t, I work!\n");
return 42;
}
And a corresponding interface file:
/* File: example.i */
%module test
%{
#include "example.h"
%}
%include "example.h"
Now I have questions. Firstly, when I want to actually run SWIG initially, am I supposed to use the example_wrap.c (from swig -java example.i) or example_wrap.cxx (from swig -c++ example.i) file when recompiling with my original example.cpp? Or perhaps both? I tried both and the latter seemed most likely, but when I recompile as so:
g++ example.cpp example_wrap.cxx -I/usr/lib/jvm/java-6-sun-.../include/
I get a host of errors regarding TcL of all things, asking me for the tcl.h header. I can't even wrap my mind around why it wants that much less needs it, and as such have found myself where I don't even know how to begin using SWIG.