我正在尝试做一个简单的示例来对 c++ 测试类进行 cythonize。我不能让它工作,为什么?
这是我的代码,非常基本:
mytest.h:
class Test
{
public:
Test(unsigned test = 0);
void print();
private:
unsigned m_test;
};
我的测试.cpp:
#include "mytest.h"
#include <iostream>
using namespace std;
Test::Test(unsigned test)
: m_test(test)
{
cout << "Test::Test" << endl;
}
void Test::print()
{
cout << "print:" << m_test << endl;
}
对于 Cython 部分,我有test.pyx:
cdef extern from "mytest.h":
cdef cppclass Test:
Test(unsigned int) except +
void print()
cdef class pyTest:
cdef Test* thisptr
def __cinit__(self, unsigned test):
self.thisptr = new Test(test)
def __dealloc__(self):
del self.thisptr
我编译:
cython --cplus test.pyx
...并获得大量错误消息,例如“Empty declarator”:
> Error compiling Cython file:
> ------------------------------------------------------------
> ...
> cdef extern from "mytest.h":
> cdef cppclass Test:
> Test(unsigned int) except +
> void print()
> ^
> ------------------------------------------------------------
>
> test.pyx:4:7: Empty declarator
>
> Error compiling Cython file:
> ------------------------------------------------------------
> ...
> cdef extern from "mytest.h":
> cdef cppclass Test:
> Test(unsigned int) except +
> void print()
> ^
> ------------------------------------------------------------
>
> test.pyx:4:7: Syntax error in C variable declaration
我没看到什么?
谢谢