Skip to content

Instantly share code, notes, and snippets.

@jcavat
Created January 13, 2021 11:06
Show Gist options
  • Save jcavat/4ed12057fb1af177886776b49c755d6e to your computer and use it in GitHub Desktop.
Save jcavat/4ed12057fb1af177886776b49c755d6e to your computer and use it in GitHub Desktop.
Python Wrapper for C++ with SWIG
%module demo
%{
#include "test.hpp"
%}
%include "test.hpp"
swig -python -c++ -o _demo.cc demo.i
python3 setup.py build_ext --inplac
python3
>> import * from demo
>> addTest(18, 24)
42
from distutils.core import setup, Extension
extension_mod = Extension("_demo", ["_demo.cc", "test.cpp"])
setup(name = "demo", ext_modules=[extension_mod])
#include "test.hpp"
int addTest(int i, int j) { return i + j; }
#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