【问题标题】:Error while trying to compile Cython output with GCC尝试使用 GCC 编译 Cython 输出时出错
【发布时间】:2015-03-26 18:02:27
【问题描述】:

我正在尝试使用 GCC 将 Cython3 文件编译为可执行文件。 目前我仍然坚持简单的“hello world”:

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

这是我为了编译这个简单的程序而尝试执行的命令:

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

第一个命令运行正确,但这是我输入第二个命令时得到的结果:

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

【问题讨论】:

  • 我删除了我的答案,因为它对你不起作用。在我的 PC 中,我使用 setup.py 解决了问题,因此我无法再真正跟踪问题以尝试解决问题。对不起,如果我浪费了你的时间。
  • 没有浪费时间,每一个建设性的回答都是解决问题的一个新步骤。感谢您的帮助!

标签: python gcc cython


【解决方案1】:

使用以下命令解决问题:

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

【讨论】:

    【解决方案2】:

    我怀疑你的回答是否能解决问题。

    您最初的问题是,扩展名为cython.pyx(考虑到this post)。

    但是,不允许将 cython 模块命名为“cython”,因为它是 Cython 的特殊名称,会导致生成的 c 文件无法编译(无论出于何种原因,插入了虚假的 typedef void PyTypeObject;)。不幸的是,cython 没有报告这种情况下的错误。

    将 pyx 文件/扩展名从 cython.pyx 重命名为 test.pyx 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-28
      • 2023-01-19
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多