Skip to content

gcc compile time error with cimport_from_pyx #3734

Closed

Description

@c-f-h

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.

Activity

  1. added a commit that references this issue on Mar 27, 2021
    9decfca
  2. added this to the 3.0 milestone on Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions