[Baypiggies] Help with ctypes
Glen Jarvis
glen at glenjarvis.com
Sat Dec 5 22:56:32 CET 2009
I'm trying to learn how to write my own C-libraries and wrap with
Python. My first stab at this was with ctypes - it looked cleaner for
what I wanted to do. I admit, however, I don't understand the error
that I seem to be getting on several tested platforms.
(Note: Here's the basic documentation: http://docs.python.org/library/ctypes.html)
Here is my very powerful and sophisticated C-library :) (demo.c):
int demo() {
return 5;
}
Compile to library (I imagine this is where I am missing a step):
gjarvis at boxee:~$ gcc -c demo.c
And, now I have a spanking good demo.o file:
gjarvis at boxee:~$ file demo.o
demo.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not
stripped
Now, when trying to access with ctypes, I keep seeing the message
"Only ET_DYN and ET_EXEC can be loaded" -- I'm not able to find any
web pages or docs to point me in the right direction. Is there
anything that I'm missing? Do I need to include <Python.h> if it's
just a one-way-wrap like this? Any direction to documentation -- or a
very small code snippet to get me started is all I think I'll need:
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> demo = ctypes.cdll.LoadLibrary('/home/gjarvis/demo.o')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in
LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/gjarvis/demo.o: only ET_DYN and ET_EXEC can be loaded
Thanks in Advance,
Glen
--
http://www.tofighthiv.org/goto/glenjarvis
I'm Riding to End AIDS
From June 6 - June12, 2010, I'm bicycling in AIDS/LifeCycle. It's a 7-
day, 545-mile bike ride from San Francisco to Los Angeles to make a
world of difference in the lives of people living with HIV and AIDS.
Please support me and the San Francisco AIDS Foundation by making a
donation.
Visit: http://www.tofighthiv.org/goto/glenjarvis
We'll keep riding until AIDS and HIV are a thing of the past.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20091205/bc840d2c/attachment.htm>
More information about the Baypiggies
mailing list