我的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时,它会对一些仅在C++模式下可用的Cython特性感到愤怒:
def __dealloc__(self):
del self.p_synth_unit
^
------------------------------------------------------------
phase_engine.pyx:74:8: Operation only allowed in c++从中我理解它忽略了我的setup.py,并以某种方式完成了自己的工作。我该如何给它所有这些参数呢?
发布于 2020-11-10 00:21:13
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)。
https://stackoverflow.com/questions/64755337
复制相似问题