473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Question: "load"ing a shared object in python

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
3 2015
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: keefah | last post by:
Hi, I can't seem to get past this problem, though I've tried multiple examples off the web. I've registered integrated Crystal (VS.NET 2003 Pro). I've made sure the assemblies are all there. I've...
2
by: santa19992000 | last post by:
Confusing th eword with "library", "shared library" and how to use these things in real C project, is there any small example I can take a look. Thanks.
1
by: Lauchlan M | last post by:
Hi. I'm using ASP.NET, getting an "Object reference not set to an instance of an object" error. In my login.aspx page I have: string arrUserRoles = new string {"UserRole"};...
2
by: Jeff_Mac | last post by:
Hi there. I'm a bit of a newbie, and I would appreciate any help that anyone can give me on an error I'm getting with Crystal Reports. Every time I attempt to view a report using the Crystal...
1
by: Dominique Vandensteen | last post by:
I want to dynamicly load a type (typename is defined in the database). This type is located in the exe itself or one of the dll's in the directory with the exe file. When creating an instance...
3
by: Kenneth Kahl | last post by:
Hello, I would like to call a C++ programm out of Java with help of JNI. By the followed command I created a "shared library": g++ -shared -o libcalculate.so rechner.cpp When I create an...
5
by: lister | last post by:
Hi all, I have a fairly diverse range of data that I want to cache in the session rather than pulling it from the database on every page refresh. The problem is is that it seems that PHP...
3
by: Michel Couche | last post by:
Hello, I have an ASP.Net application that uses the Wizard control to build a newsletter. There are three steps in the wizard. The customer's specific design data are loaded from a database in...
0
by: =?Utf-8?B?SkhhbGV5?= | last post by:
Our system is: IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram Windows Server 2003 SP2 IIS 6.0 SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server) Windows Server 2003 SP2 SQL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.