Created
September 4, 2011 19:44
-
-
Save mattbierbaum/1193397 to your computer and use it in GitHub Desktop.
SWIG with C++ class example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
class kitty { | |
public: | |
kitty(); | |
~kitty(); | |
void speak(); | |
void speak2(){ printf("totes works\n"); } | |
private: | |
int variable; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%module kitty | |
%{ | |
#include "kitty.h" | |
%} | |
%include "kitty.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i love you