I\'m new to Cython and I\'m trying to use Cython to wrap a C/C++ static library. I made a simple example as follow.
Test.h:
#ifndef
If your C++ code is only used by the wrapper, another option is to let the setup compile your .cpp file, like this:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("test",
["test.pyx", "test.cpp"],
language='c++',
)]
setup(
name = 'test',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
For linking to a static library you have to use the extra_objects argument in your Extension:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension("test",
["test.pyx"],
language='c++',
extra_objects=["libtest.a"],
)]
setup(
name = 'test',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)