How to pass flag to gcc in Python setup.py script?

天大地大妈咪最大 提交于 2019-11-26 16:40:52

问题


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'])])

回答1:


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.



来源:https://stackoverflow.com/questions/1676384/how-to-pass-flag-to-gcc-in-python-setup-py-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!