导入错误未定义符号(python 中的 C++ 模块)ZTINSt8ios_base7failureB5cxx11E
Import error undefined symbol (C++ module in python) ZTINSt8ios_base7failureB5cxx11E
我知道网站上有很多类似的问题,但我找不到问题的答案。
我正在用 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
从终端构建扩展,然后从终端 运行 .py
或来自 Anaconda 中的 Spyder(我在两种情况下都遇到了错误。)
据我了解,错误可能来自 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()]
)
在anaconda中安装libgcc
后问题解决:conda install libgcc
,缺少库。
我知道网站上有很多类似的问题,但我找不到问题的答案。
我正在用 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
从终端构建扩展,然后从终端 运行 .py
或来自 Anaconda 中的 Spyder(我在两种情况下都遇到了错误。)
据我了解,错误可能来自 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()]
)
在anaconda中安装libgcc
后问题解决:conda install libgcc
,缺少库。