By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,097 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,097 IT Pros & Developers. It's quick & easy.

Question: "load"ing a shared object in python

P: n/a
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 libx.so) 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
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Tue, 25 Jan 2005 23:19:01 +0200, Pro Grammer <a@b.c> wrote:
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 libx.so) 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++ ?


Will ctypes do the trick?

http://starship.python.net/crew/theller/ctypes/

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Jul 18 '05 #2

P: n/a
Pro Grammer <a@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 libx.so) 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:

http://docs.python.org/lib/module-dl.html

Example:
import dl, time
a=dl.open('/lib/libc.so.6')
a.call('time'), time.time()

(929723914, 929723914.498)

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

Rick
Jul 18 '05 #3

P: n/a

On Jan 28, 2005, at 6:48 AM, Rick L. Ratzel wrote:
Pro Grammer <a@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 libx.so) 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:

http://docs.python.org/lib/module-dl.html


As Simon Brunning notes, ctypes
(<http://starship.python.net/crew/theller/ctypes/>) is a robust
alternative to the `dl' module.
Example:
import dl, time
a=dl.open('/lib/libc.so.6')
a.call('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
<http://mail.python.org/pipermail/pyt...2004-November/
249513.html> for more information.

Regards,

Mark Rowe
<http://bdash.net.nz/>

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.