Newbie Developing a Python Extension

J

Jeremy

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'.

What is wrong here? Is the from-import statement right?

Why is it, when I use 'import sm' or 'from sm import...', I get the message
'ImportError: No module named sm'?

Thanks,
Jeremy
 
C

Carl Banks

Jeremy said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top