Cython unable to find shared object file

后端 未结 2 1864
青春惊慌失措
青春惊慌失措 2021-01-13 13:25

I am trying to link to my own C library from Cython, following the directions I\'ve found on the web, including this answer:

Using Cython To Link Python To A Shared

2条回答
  •  [愿得一人]
    2021-01-13 14:14

    I have fixed it by change setup.py.

    1. I have a C++ dynamic shared library called "libtmsmdreader.so". and a header file named "TmsMdReader.hpp"
    2. I wrapper C++ shared library to cython library called "tmsmdreader-pythonxxxxxx.so"
    from setuptools import setup 
    from distutils.extension import Extension
    from Cython.Build import cythonize
    
    setup(
        name="tmsmdreader",
        ext_modules=cythonize([
            Extension(
                name="tmsmdreader",
                language="c++",
                sources=["TmsMdReaderApi.pyx"],
                libraries=["tmsmdreader"],
                library_dirs=["."],
                include_dirs=["."],
                extra_compile_args=["-std=c++14"],
                compiler_directives={'language_level': 3},
                runtime_library_dirs=["."])
                ]))
    

    library_dirs=["."] and runtime_library_dirs=["."] can fixed LD_LIBRARY_PATH if libtmsmdreader.so in python scripy directory

提交回复
热议问题