如何在Python setup.py脚本中将标志传递给gcc? [英] How to pass flag to gcc in Python setup.py script?
问题描述
我正在用C编写一个Python扩展,它需要CoreFoundation框架(除其他外).可以使用以下命令进行编译:
I'm writing a Python extension in C that requires the CoreFoundation framework (among other things). This compiles fine with:
gcc -o foo foo.c -framework CoreFoundation -framework Python
(-framework"是Apple专用的gcc扩展,但这没关系,因为无论如何我都在使用它们的特定框架)
("-framework" is an Apple-only gcc extension, but that's okay because I'm using their specific framework anyway)
我如何告诉setup.py将此标志传递给gcc?
How do I tell setup.py to pass this flag to gcc?
我尝试了这个,但是它似乎不起作用(它可以编译,但是当我尝试运行它时会抱怨未定义的符号):
I tried this, but it doesn't seem to work (it compiles, but then complains of undefined symbols when I try to run it):
from distutils.core import setup, Extension
setup(name='foo',
version='1.0',
author='Me',
ext_modules=[Extension('foo',
['foo.c'],
extra_compile_args=['-framework CoreFoundation'])])
这似乎起作用:
from distutils.core import setup, Extension
setup(name='foo',
version='1.0',
author='Me',
ext_modules=[Extension('foo',
['foo.c'],
extra_link_args=['-framework', 'CoreFoundation'])])
推荐答案
也许您也需要设置extra_link_args
?编译源代码时使用extra_compile_args
,链接结果时使用extra_link_args
.
Maybe you need to set extra_link_args
, too? extra_compile_args
is used when compiling the source code, extra_link_args
when linking the result.
这篇关于如何在Python setup.py脚本中将标志传递给gcc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!