Tuesday 16 December 2008

Pitfall with distutils + OpenGL on Mac Os X

This is mainly here as a reminder to myself and anyone else who might fall into this. The scenario is as follows: I want to compile a C Python extension that uses OpenGL on Mac Os X. My setup.py file looks something like this:
#!/usr/bin/env python2.5

from distutils.core import setup, Extension

module1 = Extension('foo',
sources=['foo.c'],
extra_link_args=['-framework OpenGL'])

setup(
name='foobar',
version='0.1',
description='This is foobar!',
ext_modules=[module1]
)
However, when I build this with python setup.py build and then try to import the module with python -c 'import foo' , I get the following error:
ImportError: dlopen(./foo.so, 2): Symbol not found: _glBegin
Referenced from: .../foo.so
Expected in: dynamic lookup
How can we fix this? Take a look at the following file:
#!/usr/bin/env python2.5

from distutils.core import setup, Extension

module1 = Extension('foo',
sources=['foo.c'],
extra_link_args=['-framework', 'OpenGL']) # Note the "', '"

setup(
name='foobar',
version='0.1',
description='This is foobar!',
ext_modules=[module1]
)
So, the '-framework OpenGL' has to be given as two parameters for distutils. Nice to know.
 

Header Image

Header Image
Bitwiese Header Image