Last active
November 27, 2018 13:02
-
-
Save VitorRamos/0d315949f143e0eb73ec1a28cb8d8367 to your computer and use it in GitHub Desktop.
Swig simple example
This file contains hidden or 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 "myclass.h" | |
int myclass::get_x() | |
{ | |
return x; | |
} | |
void myclass::set_x(int v) | |
{ | |
x= v; | |
} |
This file contains hidden or 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
class myclass | |
{ | |
private: | |
int x=0; | |
public: | |
int get_x(); | |
void set_x(int); | |
}; |
This file contains hidden or 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
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 |
This file contains hidden or 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
from myclass import myclass | |
myobj= myclass() | |
myobj.set_x(12) | |
print(myobj.get_x()) |
This file contains hidden or 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 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