Mailing List Archive

Extending Python with C
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

Any ideas on what this is? I'm using Python 1.5.2, and the .c file
compiled without complaint on gcc 2.91.66. I imagine I'm missing
something simple, like a compile option for gcc, but I just can't figure
it out.

Thanks,
John


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Extending Python with C [ In reply to ]
John Fisher <jfisher@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."