Extending Python with C

Carey Evans c.evans at clear.net.nz
Sat Jun 12 19:43:48 EDT 1999


John Fisher <jfisher at are.berkeley.edu> writes:

> I'm a relative Python newbie having some trouble getting a module to
> load.  I wrote a simple one, using as a model the example given on the
> Python website, just to get the hang of it; however, when I try to load
> the compiled file I get a rather baffling error:
> 
> ImportError: ./echo.o: ELF file's phentsize not the expected size

Can you tell use what you're actually doing?  I've never encountered
this error, so I can't suggest how to fix it.  It does seem strange
that you're importing a .o file, though.

FWIW, this is my procedure for compiling one of my own extensions:

$ cat Setup.in
*shared*
iconv iconvmodule.c
$ cp /usr/lib/python1.5/config/Makefile.pre.in .
$ make -f Makefile.pre.in boot
[...]
$ make
gcc -fpic  -g -O2 -I/usr/include/python1.5 -I/usr/include/python1.5 -DHAVE_CONFIG_H -c ./iconvmodule.c
gcc -shared -lc  iconvmodule.o  -o iconvmodule.so
$ python
Python 1.5.2 (#0, Apr 21 1999, 15:19:36)  [GCC egcs-2.91.66 Debian GNU/Linux (egcs-1.1.2 release)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import iconv
>>> iconv
<module 'iconv' from './iconvmodule.so'>
>>> dir(iconv)
['INCOMPLETE', 'Iconv', 'IconvType', '__doc__', '__file__', '__name__', 'convert', 'error']

-- 
	 Carey Evans  http://home.clear.net.nz/pages/c.evans/

	     "I'm not a god.  I've just been misquoted."




More information about the Python-list mailing list