基于外部值的Cython条件编译 [英] Cython conditional compile based on external value
本文介绍了基于外部值的Cython条件编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试有条件地从Cython pxd编译(或生成)为C代码。我读到可以定义DEA值和可以根据其值有条件生成的IF,但是如何从pxd文件之外获取该值呢?
I try to conditionally compile (or generate) to c code from a Cython pxd. I read that I can DEF to define aa value and IF to conditionally generate based on its value, but how can I get this value to get from outside of the pxd file?
特别是这两种情况现在对我来说很有趣:
Specifically these two cases are interesting for me now:
- 为Cython提供了一些命令行定义,最好通过Cython.Distutils setuptools方式
- 外部C头文件定义了一些值,并根据该值有条件地使用Cython进行了定义(现在可能无法执行?)
谢谢
推荐答案
您可以生成一个pxi文件,并在执行之前包含它IF(与./configure一样,也生成config.h。)
这就是我们在Kivy setup.py中所做的,例如:
You could generate a pxi file, and include it before doing your IF (same as ./configure generate a config.h too.) This is what we do in Kivy setup.py for example :
c_options = {
'use_opengl_es2': True,
'use_opengl_debug': False,
'use_glew': False,
'use_mesagl': False}
print 'Generate config.pxi'
with open(join(dirname(__file__), 'kivy', 'graphics', 'config.pxi'), 'w') as fd:
for k, v in c_options.iteritems():
fd.write('DEF %s = %d\n' % (k.upper(), int(v)))
然后,在您的pxd中:
And then, in your pxd :
include "config.pxi"
IF USE_OPENGL_DEBUG == 1:
# do other import or whatever you want
这篇关于基于外部值的Cython条件编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文