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.

4 comments:

SDC said...

Thank you so much! I was stuck on this business with the framework arguments!

Matthew Mitchell said...

Doesn't quite work for me. It get:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/cscalelib.so, 2): Symbol not found: _glBindFramebufferEXT
Referenced from: /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/cscalelib.so
Expected in: dynamic lookup

:(

Richard Jones said...

Thankyou so much more posting this. I've just spent quite some time bashing my head against building OpenGL stuff in distutils on OS X :-(

jowdjbrown said...

You clearly know what you’re talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read? Ford Chiptuning

 

Header Image

Header Image
Bitwiese Header Image