使用Cython进行编译时找不到库文件

时间:2017-11-01 12:01:42

标签: python c++ cython

我正在构建/编译Cython项目:

setup.caller.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize

setup(
    name = 'test app',
    cmdclass = {'build_ext': build_ext},
    ext_modules = cythonize([
        Extension(
            'caller',
            ['caller.pyx', 'foo.cpp'],
            language='c++',
            extra_compile_args=['-std=c++11'],
            library_dirs=['/usr/lib/bar'],
            libraries=['libbar'],
            include_dirs=['/usr/include/baz']
        )
    ])
)

但是当我构建/编译时出现错误:

$ python setup.caller.py build_ext --inplace
...
/usr/bin/ld: cannot find -llibbar
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-g++' failed with exit status 1

我检查过,“libbar.so”在“/ usr / lib / bar”中。我在Linux Mint上编译。

1 个答案:

答案 0 :(得分:2)

我认为它应该只是bar而不是libbar,链接器知道添加lib前缀以及需要的后缀(.a.so