Import error undefined symbol (C++ module in python) ZTINSt8ios_base7failureB5cxx11E

…衆ロ難τιáo~ 提交于 2019-12-11 03:14:37

问题


I know there are lots of similar questions on the website but I couldn't find an answer to my problem.

I'm wrapping C++ classes with Cython in order to use them with Python3. After building the external module with a setup.py, when I run the python program I got the following error:

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

I'm on Ubuntu 16.04, I build the extensions from the terminal with the command line python3 setup.py build_ext --inplace, and then run the .py from the terminal or from Spyder in Anaconda (I got the error in both cases.)

From what I read the error might come from the cython compilation because i'm not linking some libraries. Is this true? If it is, could someone explain me how to do it?

I let you here my setup.py, in comments all the different setups I tried.

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:


The problem was solved after installing libgcc in anaconda: conda install libgcc, there was a missing library.



来源:https://stackoverflow.com/questions/42364197/import-error-undefined-symbol-c-module-in-python-ztinst8ios-base7failureb5cx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!