Created
January 13, 2021 11:06
-
-
Save jcavat/4ed12057fb1af177886776b49c755d6e to your computer and use it in GitHub Desktop.
Python Wrapper for C++ with SWIG
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 demo | |
%{ | |
#include "test.hpp" | |
%} | |
%include "test.hpp" |
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
swig -python -c++ -o _demo.cc demo.i | |
python3 setup.py build_ext --inplac | |
python3 | |
>> import * from demo | |
>> addTest(18, 24) | |
42 |
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 distutils.core import setup, Extension | |
extension_mod = Extension("_demo", ["_demo.cc", "test.cpp"]) | |
setup(name = "demo", ext_modules=[extension_mod]) |
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 "test.hpp" | |
int addTest(int i, int j) { return i + j; } |
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
#ifndef TEST_H | |
#define TEST_H | |
int addTest(int i, int j); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment