Skip to content

Instantly share code, notes, and snippets.

@mattbierbaum
Created September 4, 2011 19:44
Show Gist options
  • Save mattbierbaum/1193397 to your computer and use it in GitHub Desktop.
Save mattbierbaum/1193397 to your computer and use it in GitHub Desktop.
SWIG with C++ class example
#include <stdio.h>
#include "kitty.h"
kitty::kitty(){
printf("Constructor\n");
variable = 100;
}
kitty::~kitty(){
printf("Destructor\n");
variable = 0;
}
void kitty::speak(){
printf("I'm a cat.\n");
}
#include <stdio.h>
class kitty {
public:
kitty();
~kitty();
void speak();
void speak2(){ printf("totes works\n"); }
private:
int variable;
};
%module kitty
%{
#include "kitty.h"
%}
%include "kitty.h"
# standard compile options for the c++ executable
FLAGS = -fPIC
# the python interface through swig
PYTHONI = -I/usr/include/python2.6/
PYTHONL = -Xlinker -export-dynamic
# default super-target
all:
g++ -fPIC -c kitty.cc -o kitty.o
swig -c++ -python -o kitty_wrap.cxx kitty.i
g++ $(FLAGS) $(PYTHONI) -c kitty_wrap.cxx -o kitty_wrap.o
g++ $(PYTHONL) $(LIBFLAGS) -shared kitty.o kitty_wrap.o -o _kitty.so
@ikraduya
Copy link

i love you

@JinyuChata
Copy link

i love you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment