Newbie Developing a Python Extension
Carl Banks
pavlovevidence at gmail.com
Fri Nov 24 11:12:53 EST 2006
Jeremy wrote:
> Hi,
>
> I have been working on Linux 2.6.9 to adapt a C++ module to work as a Python
> extension with the following setup.py file:
>
> from distutils.core import setup, Extension
>
> sm=Extension(
> 'tdma',
> define_macros=[('__USE_POSIX199309','1')],
> include_dirs=['/usr/include','/usr/include/python2.3'],
> library_dirs=['/usr/lib'],
> sources=['Bitstrea.cpp','bytequeu.cpp','debug.cpp','dlist.cpp',
> 'GrPort.cpp','IoPort.cpp','LMEmu.cpp','LMEmuPdu.cpp',
> 'MacPyIf.cpp','per_os_clk.cpp','timer.cpp'])
>
> setup(name='MySm',
> version='0.1.0',
> description='TDMA MAC',
> ext_modules=[sm])
>
> The extension uses the POSIX call clock_gettime() and things seem fine when
> generating the tdma.so file. However, when running the Python program, at a
> line 'from tdma import init,txdn,txup,...', I get an error message saying
> 'ImportError: /home/.../tdma.so: undefined symbol: clock_gettime'.
You're missing a library. From the clock_gettime man page:
NOTE
Most systems require the program be linked with the librt
library to
use these functions.
So you need to build the extention with librt. Try adding a 'libraries
= ['rt']' option to the extension definition. (Unfortunately, on
Linux, builduing a shared object without specifying libraries needed
passes silently. It'd be nice if there was an option to require all
undefined non-Python symbols to be accounted for by some library, but
that would be a lot of work to implement.)
Carl Banks
More information about the Python-list
mailing list