일부 cython 코드를 작성 중이며 이상한 문제가 발생했습니다. 내가 파이썬에서 구조체로 C로 직접 객체를 전달하려고 시도하면, cython은 코드를 잘 생성하지만, gcc는 코드 출력을 좋아하지 않고 다음과 같은 에러를 준다. error: declaration does not declare anything
. 내가 사용Cython 오류 : 선언에서 아무 것도 선언하지 않습니다.
...
Cake; // this is the error
static Cake __pyx_convert__from_py_Cake(PyObject *);
...
:
# 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.h
using Cake = struct CakeStruct {
int a, b, c;
};
void bake(Cake batter);
과 사이 썬 : 여기 내 테스트 코드 Cython 0.21을 Anaconda에서 직접 구하고 gcc 4.8.2를 우분투 14.04와 함께 출시했습니다. 사이 썬 코드에 의해 확인 cython --cplus test.pyx
및 구문을 사용하여 생성됩니다
gcc -std=c++11 -fsyntax-only -I`...python include dir...` test.cpp
-
사람이 내 .pyx 파일에 잘못 뭐하는 거지 말해 주시겠습니까? 아니면 내가이 트릭을 한 cython 버그입니까?
좋습니다. 당신의 도움을 주셔서 감사합니다! – jeremy