Question: "load"ing a shared object in python

Mark Rowe at
Thu Jan 27 19:05:11 EST 2005

On Jan 28, 2005, at 6:48 AM, Rick L. Ratzel wrote:

> Pro Grammer <a at b.c> writes:
>> Hello, all,
>> I am not sure if this is the right place to ask, but could you kindly  
>> tell me
>> how to "load" a shared object (like into python, so that the  
>> methods in
>> the .so can be used? That too, given that the shared object was  
>> written in c++,
>> compiled with g++ ?
>> Thanks,
>> Pro Grammer
>    Will the dl standard library module help you?  From the Python docs  
> at:

As Simon Brunning notes, ctypes  
(<>) is a robust  
alternative to the `dl' module.

> Example:
>>>> import dl, time
>>>>'time'), time.time()
> (929723914, 929723914.498)

A note about this example: the `dl' call returns an integer as that is  
what the C time function returns.  time.time() in Python is implemented  
in terms of C's gettimeofday, ftime or time depending on the platform.

> I'm guessing that there might be some C++ issues, but maybe it's worth
> looking into.

As far as I am aware, neither dl nor ctypes natively support C++.  This  
is a tricky matter, due to the lack of standards for C++ ABI's covering  
name mangling and vtable layout etc.  See the thread starting at  
249513.html> for more information.


Mark Rowe

More information about the Python-list mailing list