2

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()]
)
bengo
  • 325
  • 3
  • 13
  • It depends on what symbol is undefined. You can use [`libraries` and `library_dirs` as arguments to Extension to specify what to link to](https://docs.python.org/3/distutils/setupscript.html#library-options). But there's lots of possible was of getting undefined symbols so right now it isn't answerable. – DavidW Feb 21 '17 at 12:28
  • Thank you for your answer.The problem is that the symbol name is created by Cython, so I can't recognize the source of the problem... – bengo Feb 21 '17 at 13:16

1 Answers1

3

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

bengo
  • 325
  • 3
  • 13