我正在嘗試做一個簡單的例子來cythonize C++ Test類。我無法工作,爲什麼?編譯C++時無法讓Cython工作
這裏是我的代碼,很簡單:
mytest.h:
class Test
{
public:
Test(unsigned test = 0);
void print();
private:
unsigned m_test;
};
mytest.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
...並獲取大量的錯誤消息,像e「空申報人」:
> 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
我沒有看到什麼?
謝謝
謝謝,不幸的是,我有distutils評論:( – carmellose
@carmellose可以顯示更多關於你的設置?我想知道如果位版本也可能導致這樣的問題。 – ChangeMyName
您好,這裏是我的設置: Cython版本0.19.2,Python 2.7.1(r271:86832,2013年10月7日,11:56:55)和[GCC 4.4.6 20120305(Red Hat 4.4.6-4)]在linux2上 – carmellose