1

私は、c++ Test クラスを cythonize する簡単な例を実行しようとしています。私はそれを働かせることができません、なぜですか?

これが私のコードで、非常に基本的です:

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

...そして、「空の宣言子」のような大量のエラーメッセージを取得します:

> 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

何が表示されないのですか?

ありがとう

4

2 に答える 2

0

私は数日前にまったく同じ問題を抱えていました。問題は、print() メソッドの名前にあります。正確にはわかりませんが、cython は print() が好きではありません。printtest() など、他の名前に変更した場合。それはうまくコンパイルされます。

于 2013-10-24T02:50:36.313 に答える