/ / GCCでCythonの出力をコンパイルしようとするとエラーが発生する - python、gcc、cython

GCCでCythonの出力をコンパイルしようとしたときにエラーが発生しました - python、gcc、cython

GCCを使ってCython3ファイルを実行可能ファイルにコンパイルしようとしています。 今のところ、私はまだ単純な "こんにちはの世界"にこだわりました:

# -*- coding: utf-8 -*-
if __name__ == "__main__":
print("Hello World !")

このシンプルなプログラムをコンパイルするために実行しようとしたコマンドは次のとおりです:

cython3 test.pyx
gcc -I/usr/include/python3.4 test.c

最初のコマンドは正しく実行されますが、ここでは2番目のコマンドを入力すると次のようになります。

cython.c:422:14: error: conflicting types for ‘PyTypeObject’
typedef void PyTypeObject;
^
In file included from /usr/include/python3.4/pytime.h:6:0,
from /usr/include/python3.4/Python.h:65,
from cython.c:16:
/usr/include/python3.4/object.h:422:3: note: previous declaration of ‘PyTypeObject’ was here
} PyTypeObject;
^
cython.c: In function ‘__Pyx_PyObject_GetAttrStr’:
cython.c:488:18: warning: dereferencing ‘void *’ pointer
if (likely(tp->tp_getattro))
^
cython.c:399:43: note: in definition of macro ‘likely’
#define likely(x)   __builtin_expect(!!(x), 1)
^
cython.c:488:18: error: request for member ‘tp_getattro’ in something not a structure or union
if (likely(tp->tp_getattro))
^
cython.c:399:43: note: in definition of macro ‘likely’
#define likely(x)   __builtin_expect(!!(x), 1)
^
cython.c:489:18: warning: dereferencing ‘void *’ pointer
return tp->tp_getattro(obj, attr_name);
^
cython.c:489:18: error: request for member ‘tp_getattro’ in something not a structure or union

私は現在Debianのテストを行っていますので、PythonとCythonの次のバージョンがあります:

Python: 3.4.2-2
Cython: 0.21.1-1

回答:

回答№1は1

次のコマンドを使用して問題を解決しました。

cython3 test.pyx
gcc -I/usr/include/python3.4m test.c -lpython3.4m

回答№2の場合は0

私はあなたの答えが問題を解決するのを疑う。

元の問題は、拡張機能が呼び出されたことでした cython.pyx (考慮に入れる この郵便受け)。

しかし、Cythonの特別な名前であり、コンパイルできない生成されたcファイルにつながるので、あなたのcythonモジュールに "cython"という名前を付けることは許されません。 typedef void PyTypeObject; 挿入されます)。不幸にも、このケースではcythonはエラーを報告しません。

pyx-file / extensionの名前を変更する cython.pyxtest.pyx 問題を解決しました。