Sto cercando di compilare un file Cython3 in un eseguibile usando GCC. Per il momento sono ancora bloccato con un semplice "ciao mondo":
# -*- coding: utf-8 -*-
if __name__ == "__main__":
print("Hello World !")
Ecco il comando che ho provato ad eseguire per compilare questo semplice programma:
cython3 test.pyx
gcc -I/usr/include/python3.4 test.c
Il primo comando viene eseguito correttamente, ma ecco cosa ottengo quando scrivo il secondo:
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
Attualmente sto girando su Debian testing e quindi ho le seguenti versioni di Python e Cython:
Python: 3.4.2-2
Cython: 0.21.1-1
risposte:
1 per risposta № 1Problema risolto utilizzando i seguenti comandi:
cython3 test.pyx
gcc -I/usr/include/python3.4m test.c -lpython3.4m
0 per risposta № 2
Dubito che la tua risposta risolva il problema.
Il tuo problema originale era che l'estensione era stata chiamata cython.pyx
(tenere in considerazione questo post).
Tuttavia, non è permesso nominare il tuo cython-module "cython" perché è un nome speciale per Cython e porta a un c-file generato che non può essere compilato (per qualsiasi motivo spurio typedef void PyTypeObject;
è inserito). Sfortunatamente, cython non riporta un errore per questo caso.
Rinominare il file pyx / estensione da cython.pyx
a test.pyx
risolto il problema.