Undefined symbol when importing a cython module making use of another cython module

后端 未结 1 988
刺人心
刺人心 2021-01-13 20:34

I\'m working on wrapping a set of C functions using Cython into a module. I would like to be able to cimport this first module into subsequent Cython-based projects, but I a

1条回答
  •  醉梦人生
    2021-01-13 21:25

    I was able to get this to work by doing the following:

    First, specify the exModA library for linking in your exModB/setup.py file as follows:

    from distutils.core import setup, Extension
    from Cython.Build import cythonize
    
    ext = Extension('exModB/exModB',
                    sources=['exModB/exModB.pyx'],
                    libraries=['exModA'],
                    library_dirs=['/home/MyFolder/exModA'],
                    runtime_library_dirs=['/home/MyFolder/exModA']
                    )
    setup(name='exModB', ext_modules = cythonize(ext))
    

    (Instead of specifying a runtime library directory, I recommend moving exModA.so to a folder on your library search path.)

    I also had to rename exModA.so to libexModA.so so that gcc could find it. Do this after building exModA.so, but before building exModB.so:

    python exModA/setup.py build_ext --inplace
    cp exModA/exModA.so exModA/libexModA.so
    python exModB/setup.py build_ext --inplace
    

    You will probably want to tweak this, but it should get you started.

    0 讨论(0)
提交回复
热议问题