0

我的 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 并以某种方式自己做。我如何给它所有这些参数?

4

1 回答 1

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)。

于 2020-11-09T16:21:12.930 回答