如何在 Python setup.py 脚本中将标志传递给 gcc?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1676384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass flag to gcc in Python setup.py script?
提问by Michael
I'm writing a Python extension in C that requires the CoreFoundation framework (among other things). This compiles fine with:
我正在用 C 编写一个 Python 扩展,它需要 CoreFoundation 框架(除其他外)。这编译得很好:
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)
(“-framework”是仅限 Apple 的 gcc 扩展,但这没关系,因为无论如何我都在使用他们的特定框架)
How do I tell setup.py to pass this flag to gcc?
我如何告诉 setup.py 将此标志传递给 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'])])
采纳答案by Luká? Lalinsky
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.
也许你也需要设置extra_link_args
?extra_compile_args
在编译源代码和extra_link_args
链接结果时使用。