Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc compile time error with cimport_from_pyx #3734

Closed
c-f-h opened this issue Jul 8, 2020 · 0 comments · Fixed by #3743
Closed

gcc compile time error with cimport_from_pyx #3734

c-f-h opened this issue Jul 8, 2020 · 0 comments · Fixed by #3743

Comments

@c-f-h
Copy link
Contributor

c-f-h commented Jul 8, 2020

The following setup with 2 pyx files and the corresponding setup.py to build them results in a gcc compile time error:

#>>> moda.pyx

cdef class ClassA:
    cdef int[2] a

#>>> modb.pyx

from moda cimport ClassA

cdef class ClassB(ClassA):
    cdef int[2] b

#>>> setup.py

from setuptools import setup
from Cython.Build import cythonize
import Cython.Compiler.Options

Cython.Compiler.Options.cimport_from_pyx = True

setup(
        ext_modules = cythonize(["moda.pyx", "modb.pyx"],
            compiler_directives={'language_level': 3})
)

The error is as follows:

$ python setup.py build
running build
running build_ext
building 'modb' extension
gcc -pthread -B /home/clemens/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/clemens/miniconda3/include/python3.7m -c modb.c -o build/temp.linux-x86_64-3.7/modb.o
modb.c:2585:32: error: redefinition of ‘__Pyx_carray_to_py_int’
 static CYTHON_INLINE PyObject *__Pyx_carray_to_py_int(int *__pyx_v_v, Py_ssize_t __pyx_v_length) {
                                ^~~~~~~~~~~~~~~~~~~~~~
modb.c:2038:32: note: previous definition of ‘__Pyx_carray_to_py_int’ was here
 static CYTHON_INLINE PyObject *__Pyx_carray_to_py_int(int *__pyx_v_v, Py_ssize_t __pyx_v_length) {
                                ^~~~~~~~~~~~~~~~~~~~~~
modb.c:2696:32: error: redefinition of ‘__Pyx_carray_to_tuple_int’
 static CYTHON_INLINE PyObject *__Pyx_carray_to_tuple_int(int *__pyx_v_v, Py_ssize_t __pyx_v_length) {
                                ^~~~~~~~~~~~~~~~~~~~~~~~~
modb.c:2149:32: note: previous definition of ‘__Pyx_carray_to_tuple_int’ was here
 static CYTHON_INLINE PyObject *__Pyx_carray_to_tuple_int(int *__pyx_v_v, Py_ssize_t __pyx_v_length) {
                                ^~~~~~~~~~~~~~~~~~~~~~~~~
modb.c:2804:12: error: redefinition of ‘__Pyx_carray_from_py_int’
 static int __Pyx_carray_from_py_int(PyObject *__pyx_v_o, int *__pyx_v_v, Py_ssize_t __pyx_v_length) {
            ^~~~~~~~~~~~~~~~~~~~~~~~
modb.c:2257:12: note: previous definition of ‘__Pyx_carray_from_py_int’ was here
 static int __Pyx_carray_from_py_int(PyObject *__pyx_v_o, int *__pyx_v_v, Py_ssize_t __pyx_v_length) {
            ^~~~~~~~~~~~~~~~~~~~~~~~
error: command 'gcc' failed with exit status 1

The issue seems to be that certain utility functions are getting inserted into the C source file multiple times. The error goes away if cimport_from_pyx is disabled and a moda.pxd file is generated manually.

This is Python 3.7.4, Cython 0.29.20, Linux (WSL) with gcc 7.5.0.

da-woods added a commit to da-woods/cython that referenced this issue Jul 17, 2020
scoder pushed a commit that referenced this issue Mar 27, 2021
* Avoid UtilityCode from cimport_from_pyx files
* Unique names for generated cfunc wrappers, avoid pxd pickle code
* Set .in_pxd on nodes prior to analyse_declarations

Fixes #3716
Fixes #3741
Fixes #3734
@scoder scoder added this to the 3.0 milestone Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants