简体   繁体   English

尝试使用GCC编译Cython输出时出错

[英]Error while trying to compile Cython output with GCC

I'm trying to compile a Cython3 file into an executable using GCC. 我正在尝试使用GCC将Cython3文件编译为可执行文件。 For the moment I'm still stuck with a simple "hello world" : 目前,我仍然停留在一个简单的“ hello world”中:

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

Here is the command I've tried to execute in order to compile this simple program : 这是我尝试执行以编译此简单程序的命令:

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

The first command run correctly, but here is what I get when I type the second one : 第一个命令可以正确运行,但是这是我输入第二个命令时得到的:

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

I'm currently running on Debian testing, and therefore I have the following versions of Python and Cython : 我目前正在Debian测试中运行,因此具有以下版本的Python和Cython:

Python: 3.4.2-2
Cython: 0.21.1-1

Problem solved using the following commands : 使用以下命令解决了问题:

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

I doubt your answer solves the problem. 我怀疑您的回答是否可以解决问题。

Your original problem was, that the extension was called cython.pyx (taking into account this post ). 您最初的问题是,该扩展名为cython.pyx (考虑到此帖子 )。

However, it is not allowed to name your cython-module "cython" because it is a special name for Cython and leads to a generated c-file which cannot be compiled (for whatever reason spurious typedef void PyTypeObject; is inserted). 但是,不允许将您的cython模块命名为“ cython”,因为它是Cython的特殊名称,并导致生成的c文件无法编译(由于任何原因typedef void PyTypeObject;会插入虚假的typedef void PyTypeObject; )。 Unluckily cython doesn't report an error for this case. 不幸的是,cython在这种情况下没有报告错误。

Renaming the pyx-file/extension from cython.pyx to test.pyx solved the issue. 将pyx文件/扩展名从cython.pyx重命名为test.pyx解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM