| 1 |
# tag: cpp |
| 2 |
PYTHON setup.py build_ext --inplace |
| 3 |
PYTHON -c "import test" |
| 4 |
|
| 5 |
######## test.pyx ######## |
| 6 |
# distutils: language = c++ |
| 7 |
|
| 8 |
cdef extern from "test.h": |
| 9 |
ctypedef struct c_Test "Test": |
| 10 |
const char *getString() except +RuntimeError |
| 11 |
|
| 12 |
cdef class Test: |
| 13 |
cdef c_Test *thisptr |
| 14 |
def getString(self): |
| 15 |
return self.thisptr.getString() |
| 16 |
|
| 17 |
######## test.h ######## |
| 18 |
|
| 19 |
static const char *astring = "123"; |
| 20 |
class Test { |
| 21 |
public: |
| 22 |
const char *getString(void) { return astring; } |
| 23 |
}; |
| 24 |
|
| 25 |
######## setup.py ######## |
| 26 |
|
| 27 |
from distutils.core import setup |
| 28 |
from Cython.Build.Dependencies import cythonize |
| 29 |
|
| 30 |
setup(name='test', ext_modules=cythonize('*.pyx')) |