Skip to content

Instantly share code, notes, and snippets.

@VitorRamos
Last active November 27, 2018 13:02
Show Gist options
  • Save VitorRamos/0d315949f143e0eb73ec1a28cb8d8367 to your computer and use it in GitHub Desktop.
Save VitorRamos/0d315949f143e0eb73ec1a28cb8d8367 to your computer and use it in GitHub Desktop.
Swig simple example
#include "myclass.h"
int myclass::get_x()
{
return x;
}
void myclass::set_x(int v)
{
x= v;
}
class myclass
{
private:
int x=0;
public:
int get_x();
void set_x(int);
};
sudo apt install python3-dev swig
swig -o myclass_wrap.cpp -c++ -python myclass.i
g++ -c -fPIC myclass.cpp myclass_wrap.cpp -I /usr/include/python3.6
g++ -shared myclass.o myclass_wrap.o -o _myclass.so
from myclass import myclass
myobj= myclass()
myobj.set_x(12)
print(myobj.get_x())
%module myclass
%{
#include "myclass.h"
%}
%include "myclass.h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment