导入错误未定义符号(python中的C ++模块)ZTINSt8ios_base7failureB5cxx11E

时间:2017-02-21 10:02:14

标签: python-3.x cython cythonize

我知道网站上有很多类似的问题,但我找不到问题的答案。

我用Cython包装C ++类,以便在Python3中使用它们。使用setup.py构建外部模块后,当我运行python程序时出现以下错误:

from "name of.pyx file" import "name of the class to import" Import error: /home/.../filename.so: undefined symbol: _ZTINSt8ios_base7failureB5cxx11E.

我在Ubuntu 16.04上,我使用命令行python3 setup.py build_ext --inplace从终端构建扩展,然后从终端或从Anaconda的Spyder运行.py(我得到了两种情况都有错误。)

从我读到的错误可能来自cython编译,因为我没有链接某些库。这是真的?如果是的话,有人可以解释我该怎么做吗?

我告诉你setup.py,我在评论中尝试了所有不同的设置。

setup.py

from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy

#setup(ext_modules = cythonize(
       #"pycoralv1.pyx",             # our Cython source
       #sources=["coralv1cpp.cpp"],  # additional source file(s)
       #language="c++",              # generate C++ code
  #))

#setup(ext_modules = cythonize(Extension(
#           "pyCoralv1",                                # the extension name
#           sources=["pyCoralv1.pyx", "Coralv1cpp.cpp"], # the Cython source and
                                              # additional C++ source files
#           language="c++",                        # generate and compile C++ code
#      )))

#setup(
#    name = "testcoral",
#    ext_modules = cythonize('*.pyx'),
#)

ext_modules = [
    Extension(
        "pyCoralv1",
        sources=["pyCoralv1.pyx", "Coralv1cpp.cpp"],
        extra_compile_args=['-fopenmp',"-fPIC"],
        extra_link_args=['-fopenmp',"-I", "/usr/include/glib-2.0", "-l", "glib-2.0", "-I", "/usr/lib/x86_64-linux-gnu/glib-2.0/include"],
        language="c++",
    )
]

for e in ext_modules:
    e.pyrex_directives = {"boundscheck": False}

setup(
    name='Coral library',
    ext_modules=cythonize(ext_modules),
    include_dirs = [numpy.get_include()]
)

1 个答案:

答案 0 :(得分:4)

在anaconda libgcc中安装conda install libgcc后,问题得以解决,但是有一个丢失的库。