【问题标题】:buildozer + Cython + C++ library: dlopen failed: cannot locate symbol symbol-name referenced by module.sobuildozer + Cython + C++ 库:dlopen 失败:找不到 module.so 引用的符号符号名称
【发布时间】:2021-02-21 13:46:08
【问题描述】:

phase_engine.so 尝试使用_ZTINSt6__ndk18ios_base7failureE 却找不到:

11-08 19:59:00.629 25777 25823 I python  :  Traceback (most recent call last):
11-08 19:59:00.629 25777 25823 I python  :    File "/home/sonoflilit/phase/phase/.buildozer/android/app/main.py", line 14, in <module>
11-08 19:59:00.629 25777 25823 I python  :  ImportError: dlopen failed: cannot locate symbol "_ZTINSt6__ndk18ios_base7failureE" referenced by "/data/data/il.co.loris.phase/files/app/_python_bundle/site-packages/phase_engine.so"...
11-08 19:59:00.630 25777 25823 I python  : Python for android ended.

存在于libc++_shared.so:

apk$ readelf -s --wide lib/armeabi-v7a/libc++_shared.so | grep _ZTINSt6__ndk18ios_base7failureE
   690: 000885c0    12 OBJECT  GLOBAL DEFAULT   17 _ZTINSt6__ndk18ios_base7failureE

不是phase_engine.so动态链接的

apk/assets$ readelf -a _python_bundle/site-packages/phase_engine.so | grep lib
 0x00000001 (NEEDED)                     Shared library: [libpython3.8m.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
  000000: Rev: 1  Flags: BASE  Index: 1  Cnt: 1  Name: build/lib.linux-x86_64-3.8/phase_engine.cpython-38-x86_64-linux-gnu.so
  000000: Version: 1  File: libc.so  Cnt: 1
  0x0020: Version: 1  File: libdl.so  Cnt: 1

尽管我在setup.py 中很好地询问了libraries = ['c++'],(肯定会运行):

from setuptools import setup, Extension
from Cython.Build import cythonize

setup(
    name = 'phase-engine',
    version = '0.1',
    ext_modules = cythonize([Extension("phase_engine",
        ["phase_engine.pyx"] + ['music-synthesizer-for-android/src/' + p for p in [
            ..., 'synth_unit.cc'
        ]],
        include_path = ['music-synthesizer-for-android/src/'],
        language = 'c++',
        libraries = ['c++'],
    )])
)

我做错了什么?

【问题讨论】:

    标签: c++ cython buildozer python-for-android


    【解决方案1】:

    首先,c++ 当然应该是c++_shared,因为库被称为libc++_shared.so

    其次,我无法让它与 setup.py 一起使用,但是通过配方向环境添加编译器标志很容易,numpy 配方就是这样做的:

    class MyRecipe(IncludedFilesBehaviour, CppCompiledComponentsPythonRecipe):
        version = 'stable'
        src_filename = "../../../phase-engine"
        name = 'phase-engine'
    
        depends = ['setuptools']
    
        call_hostpython_via_targetpython = False
        install_in_hostpython = True
    
        def get_recipe_env(self, arch):
            env = super().get_recipe_env(arch)
            env['LDFLAGS'] += ' -lc++_shared'
            return env
    
    recipe = MyRecipe()
    

    【讨论】:

    • 我在 numpy 的食谱中没有找到任何 -lc++_shared 方法的证据。你在哪里找到它?看起来这样做的方法是设置 need_stl_shared 配方属性:github.com/kivy/python-for-android/blob/develop/…
    • 我想我看了一个旧版本。我很确定我在 numpy 食谱中找到了这一行,但我也在许多其他食谱中看到了它。 need_stl_shared 是我的第一个选择,但不幸的是要么没有工作,要么打破了不同的步骤(不记得)
    • 谢谢,也许搜索补丁历史会找到它。如果我没记错的话,need_stl_shared 工作正常,-lc++_shared 没有为我解决它,我认为它已经链接到那个或什么的。我通常使用 python-for-android develop 分支,所以它可能是一个新的修复程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 2017-03-21
    相关资源
    最近更新 更多