【问题标题】:python-for-android, Cython, C++, CythonRecipe: Operation only allowed in c++python-for-android、Cython、C++、CythonRecipe:只允许在 c++ 中进行操作
【发布时间】:2020-11-09 16:21:12
【问题描述】:

我的 Cython 项目有这个 setup.py:

from setuptools import setup
from Cython.Build import cythonize

setup(
    name = 'phase-engine',
    version = '0.1',
    ext_modules = cythonize(["phase_engine.pyx"] + ['music-synthesizer-for-android/src/' + p for p in [
            'fm_core.cc', 'dx7note.cc', 'env.cc', 'exp2.cc', 'fm_core.cc', 'fm_op_kernel.cc', 'freqlut.cc', 'lfo.cc', 'log2.cc', 'patch.cc', 'pitchenv.cc', 'resofilter.cc', 'ringbuffer.cc', 'sawtooth.cc', 'sin.cc', 'synth_unit.cc'
        ]],
        include_path = ['music-synthesizer-for-android/src/'],
        language = 'c++',
    )
)

当我运行 buildozer 时,它对某些 Cython 功能仅在 C++ 模式下可用感到愤怒:

    def __dealloc__(self):
        del self.p_synth_unit
       ^
------------------------------------------------------------

phase_engine.pyx:74:8: Operation only allowed in c++

据我了解,它忽略了我的 setup.py 并以某种方式自己做。我如何给它所有这些参数?

【问题讨论】:

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


    【解决方案1】:

    CythonRecipe 不适用于导入 C/C++ 代码的 Cython 代码。尝试CompiledComponentsPythonRecipe,或者如果您遇到#include <ios> 或C++ STL 中的其他问题,CppCompiledComponentsPythonRecipe

    from pythonforandroid.recipe import IncludedFilesBehaviour, CppCompiledComponentsPythonRecipe
    import os
    import sys
    
    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()
    

    由于一些奇怪的东西,对setuptools 的依赖是必不可少的,否则你会得到一个错误no module named setuptools。另外两个标志也与该错误有关,互联网说它们是相关的,所以我尝试了值组合,直到一个有效。

    LDFLAGS 解决了我后来遇到的一个问题(请参阅buildozer + Cython + C++ library: dlopen failed: cannot locate symbol symbol-name referenced by module.so)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2016-08-14
      • 1970-01-01
      • 2021-03-22
      相关资源
      最近更新 更多