23

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'])])
Michael
  • 4,700
  • 9
  • 35
  • 42

1 Answers1

19

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.

Lukáš Lalinský
  • 40,587
  • 6
  • 104
  • 126
  • Sorry; after deleting the "build" directory and re-building it seems to work. Thanks! – Michael Nov 05 '09 at 01:29
  • 2
    After finding this I found the list of available arguments helpful. http://docs.python.org/distutils/apiref.html?highlight=extension#distutils.core.Extension Thanks for pointing me in the right direction. – Joel Mar 01 '12 at 17:44