Calling a shared library using C types

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Mar 24 21:26:32 EDT 2008


En Mon, 24 Mar 2008 19:56:08 -0300, Nathan Harmston  
<iwanttobeabadger at googlemail.com> escribió:

> import ctypes
> t = ctypes.CDLL('./Simulation.so')
> this works fine, I have a simple function I ve put in for testing which  
> just
> returns the integer 4. However when I try to access this function it  
> doesnt
> work
> t.test()
>  File "<stdin>", line 1, in <module>
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
> line 325, in __getattr__
>     func = self.__getitem__(name)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
> line 330, in __getitem__
>     func = self._FuncPtr((name_or_ordinal, self))
> AttributeError: dlsym(0x81e6b0, test): symbol not found

Looks like the symbol isn't public - probably if you try loading the  
library with a C program it won't find it either. How is the function  
declared in the source?
Try listing all public symbols with: nm -D Simulation.so

> Im hoping python-list is ok for questions regarding ctypes :S

It's not off topic, although there is a specific list for ctypes-related  
questions. But hijacking a thread to post a completely different question  
is not good netiquette.

-- 
Gabriel Genellina




More information about the Python-list mailing list