【发布时间】:2014-11-24 02:55:18
【问题描述】:
我正在编写一些 cython 代码,但遇到了一个奇怪的问题。当我尝试将对象直接从 python 传递到 C 作为结构时,cython 生成代码很好,但 gcc 不喜欢代码输出并给我以下错误:error: declaration does not declare anything。这是我的测试代码:
// cake.h
using Cake = struct CakeStruct {
int a, b, c;
};
void bake(Cake batter);
和赛通:
# test.pyx
cdef extern from "cake.h":
void bake(Cake batter)
ctypedef struct Cake:
int a
int b
int c
def make_one(batter):
cdef Cake more_batter;
more_batter.a = 5
more_batter.b = 10
print(more_batter.a + more_batter.b)
bake(more_batter)
bake(batter) # <- this line generates bad code
如果查看生成的代码,坏行如下所示:
...
Cake; // this is the error
static Cake __pyx_convert__from_py_Cake(PyObject *);
...
我直接使用 Anaconda 的 cython 0.21 和 Ubuntu 14.04 附带的 gcc 4.8.2。 Cython 代码使用cython --cplus test.pyx 生成,语法检查:
gcc -std=c++11 -fsyntax-only -I`...python include dir...` test.cpp
--
谁能告诉我我在 .pyx 文件中做错了什么?或者这是我绊倒的 cython 错误?
【问题讨论】: