Calling function in shared lib
Olaf Wasmuth
olaf at wasmuth.net
Fri Jun 6 06:51:49 EDT 2003
More information about the Python-list mailing list
Fri Jun 6 06:51:49 EDT 2003
- Previous message (by thread): Calling function in shared lib
- Next message (by thread): Fixed-length fields in Martel
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Thomas Heller wrote: > Olaf Wasmuth <owasmuth at web.de> writes: > >> I am trying to write python code that is able to invoke >> a function that was compiled into a shared library >> (actually, FORTRAN routines). I did succeed for a specific >> routine in a specific library, but now I want to do this >> in a more flexible way. >> >> That is, given the library path and the "signature" of the >> routine (e.g. from a configuration file) at run time, I >> would like to call this function from within Python. My >> target platform is Unix (Solaris), so I'm thinking of >> using the GNU libltdl to access the library and do the >> call. But how can I feed the parameters into it ? Did >> anybody do this already, or do you have some pointers >> for me ? > > Sounds almost like ctypes: > http://starship.python.net/crew/theller/ctypes/ > although I've never heard it runs on Solaris. > > But I'll gladly accept patches! > > Thomas Hi Thomas, the good news is that ctypes works seems to work (at least somewhat) under Solaris (!!!): #!/usr/bin/env python from ctypes import * libc = cdll.LoadLibrary("/lib/libc.so") print libc libc.sleep( c_int(3) ) print libc.sleep I get: <CDLL '/lib/libc.so', handle ff200960 at ee380> ... and then, after 3 seconds ... <ctypes._CdeclFuncPtr object at 0xe2200> Nice tool, thanks for your suggestion ! Now I have to see how this works out with compiled FORTRAN routines ... Regards, Olaf. -- Python makes me miss Smalltalk less
- Previous message (by thread): Calling function in shared lib
- Next message (by thread): Fixed-length fields in Martel
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list