如何在Python setup.py 脚本中将标志传递给gcc?
我正在用 C 语言编写一个 Python 扩展,它需要 CoreFoundation 框架(除其他外)。这可以很好地编译:(
gcc -o foo foo.c -framework CoreFoundation -framework Python
“-framework”是 Apple 独有的 gcc 扩展,但这没关系,因为我无论如何都在使用他们的特定框架)
如何告诉 setup.py 将此标志传递给 gcc?
我尝试了这个,但它似乎不起作用(它可以编译,但当我尝试运行它时抱怨未定义的符号):
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'])])
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" is an Apple-only gcc extension, but that's okay because I'm using their specific framework anyway)
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'])])
Edit:
This appears to work:
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'])])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您还需要设置
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.