如何解决python-for-android,Cython,C ++,CythonRecipe:仅在c ++中允许操作
我的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并以某种方式自行执行。如何给所有这些参数?
解决方法
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)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。