本文介绍了pyopencl导入错误cffi.so未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功安装pyopencl,但出现导入错误.我被困在这里,无法进一步发展.任何帮助将不胜感激

I successfully installed the pyopencl but I am getting an import error. I am stuck here and unable to progress further. Any help would be much appreciated

ImportError跟踪(最近一次通话最后一次) 在()

ImportError Traceback (most recent call last) in ()

  5 from __future__ import division

  6 import numpy as np

----> 7导入pyopencl

----> 7 import pyopencl

  8 import pyopencl.array

  9 import math, time

在()中

/home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/ init .py 32

/home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/init.py in () 32

 33 try:

---> 34将pyopencl.cffi_cl导入为_cl

---> 34 import pyopencl.cffi_cl as _cl

 35 except ImportError:

 36     import os

(p)中的

/home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/cffi_cl.py

/home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/cffi_cl.py in ()

 37 from pytools import memoize_method

 38

---> 39从pyopencl._cffi导入ffi作为_ffi

---> 39 from pyopencl._cffi import ffi as _ffi

 40 from .compyte.array import f_contiguous_strides, c_contiguous_strides

 41

导入错误:/home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/_cffi.so:未定义的符号:_ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE

ImportError: /home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/_cffi.so: undefined symbol: _ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE

推荐答案

问题是libstdc++中的nofollow noreferrer>双重ABI std::stringstd::list的gcc5.1. Anaconda现在安装libstdc++.so.6.0.19(大概是因为他们已经添加了带有C ++库的Python包)来自gcc 4.8.3和pre dual ABI ,其中Ubuntu 16.04随附了gcc 5.4和libstdc++.6.0.21.当您构建pyopencl时,它会针对您的系统libstdc++进行构建和链接,但是当您尝试导入pyopencl时,它会与Anaconda动态链接并无法找到符号.

The problem is the the dual ABI in libstdc++ with gcc5.1 for std::string and std::list. Anaconda now installs libstdc++.so.6.0.19 (presumably because they've added a Python package with a C++ library) from gcc 4.8.3 and pre dual ABI where as Ubuntu 16.04 comes with gcc 5.4 and libstdc++.6.0.21. When you build pyopencl it builds and links against your system libstdc++ but when you try to import pyopencl it dynamically links against the Anaconda one and fails to find the symbols.

应该可以通过在pyopencl siteconf.pyCXXFLAGS列表中添加-D_GLIBCXX_USE_CXX11_ABI=0来解决此问题.这样可以解决std::string问题,但缺少其他符号:

It should be possible to solve this by adding -D_GLIBCXX_USE_CXX11_ABI=0 to the CXXFLAGS list in the pyopencl siteconf.py. That solves the std::string issue but has other missing symbols:

ImportError: /home/cryan/anaconda3/lib/python3.6/site-packages/pyopencl-2016.2.1-py3.6-linux-x86_64.egg/pyopencl/_cffi.abi3.so: undefined symbol: _ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFvvE

您的选择是:

  1. 从Anaconda(conda install gcc)安装gcc并使用它构建pyopencl.不幸的是,如果您的PATH上有Anaconda,那么您将在各处使用它们的gcc.
  2. 只需删除/重命名~/anaconda3/lib中的libstdc++:cd ~/anaconda3/lib; mv libstdc++.so libstdc++.annoying; mv libstdc++.so.6 libstdc++.annoying.6. Python模块将在您的系统中找到一个应该向后兼容的模块.
  1. Install gcc from Anaconda (conda install gcc) and build pyopencl using that. Unfortunately if you have Anaconda on your PATH you'll use their gcc everywhere.
  2. Just delete/rename the libstdc++ in ~/anaconda3/lib: cd ~/anaconda3/lib; mv libstdc++.so libstdc++.annoying; mv libstdc++.so.6 libstdc++.annoying.6. Python modules will find your system one which should be backwards compatible.

这篇关于pyopencl导入错误cffi.so未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-05 19:35