ctypes: loading .so file on Linux

Discussion in 'Python' started by Paddy, Aug 23, 2008.

  1. Paddy

    Paddy Guest

    Hi,
    I am am falling at the first hurdle when trying to access a library
    using ctypes.

    I have a file libucdb.so which the file command says is shared object,
    but I cannot get it to load:

    Any help would be appreciated:

    dmccarthy: file /opt/questasim_6.4/questasim/linux/libucdb.a /opt/
    questasim_=
    6.4/questasim/linux/libucdb.so
    /opt/questasim_6.4/questasim/linux/libucdb.a: current ar archive
    /opt/questasim_6.4/questasim/linux/libucdb.so: ELF 32-bit LSB shared
    object,=
    Intel 80386, version 1 (SYSV), not stripped
    dmccarthy: python
    ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
    Python 2.5.1 (r251:54863, May 2 2007, 08:46:07)
    [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> cdll.LoadLibrary("libc.so.6")

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    NameError: name 'cdll' is not defined
    >>> from ctypes import *
    >>> ^[[A^[[A

    ^e "<stdin>", line 1
    SyntaxError: invalid syntax
    >>> cdll.LoadLibrary("libc.so.6")

    <CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490>
    >>> cdll.LoadLibrary("libucdb.so")

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    lib/pyth=
    on2.5/ctypes/__init__.py", line 423, in LoadLibrary
    return self._dlltype(name)
    File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    lib/pyth=
    on2.5/ctypes/__init__.py", line 340, in __init__
    self._handle =3D _dlopen(self._name, mode)
    OSError: libucdb.so: cannot open shared object file: No such file or
    directo=
    ry
    >>> cdll.LoadLibrary("libc.so.6")

    <CDLL 'libc.so.6', handle 2a958a2900 at 2a95df3ad0>
    >>> libc =3D CDLL("libc.so.6")
    >>> libc

    <CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490>
    >>> libc =3D CDLL("libucdb.so")

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    lib/pyth=
    on2.5/ctypes/__init__.py", line 340, in __init__
    self._handle =3D _dlopen(self._name, mode)
    OSError: libucdb.so: cannot open shared object file: No such file or
    directo=
    ry
    >>> libc =3D CDLL("/opt/questasim_6.4/questasim/linux/libucdb.so")

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    lib/pyth=
    on2.5/ctypes/__init__.py", line 340, in __init__
    self._handle =3D _dlopen(self._name, mode)
    OSError: /opt/questasim_6.4/questasim/linux/libucdb.so: cannot open
    shared o=
    bject file: No such file or directory
    >>> ^[[A

    File "<stdin>", line 1
    ^
    SyntaxError: invalid syntax
    >>>


    - Paddy.
     
    Paddy, Aug 23, 2008
    #1
    1. Advertising

  2. Paddy

    Paddy Guest

    On Aug 23, 2:33 pm, Paddy <> wrote:
    > Hi,
    > I am am falling at the first hurdle when trying to access a library
    > using ctypes.
    >
    > I have a file libucdb.so which the file command says is shared object,
    > but I cannot get it to load:
    >
    > Any help would be appreciated:
    >
    > dmccarthy: file /opt/questasim_6.4/questasim/linux/libucdb.a /opt/
    > questasim_=
    > 6.4/questasim/linux/libucdb.so
    > /opt/questasim_6.4/questasim/linux/libucdb.a:  current ar archive
    > /opt/questasim_6.4/questasim/linux/libucdb.so: ELF 32-bit LSB shared
    > object,=
    >  Intel 80386, version 1 (SYSV), not stripped
    > dmccarthy: python
    > ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
    > Python 2.5.1 (r251:54863, May  2 2007, 08:46:07)
    > [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
    > Type "help", "copyright", "credits" or "license" for more information.>>> cdll.LoadLibrary("libc.so.6")
    >
    > Traceback (most recent call last):
    >   File "<stdin>", line 1, in <module>
    > NameError: name 'cdll' is not defined>>> from ctypes import *
    > >>> ^[[A^[[A

    >
    >     ^e "<stdin>", line 1
    > SyntaxError: invalid syntax>>> cdll.LoadLibrary("libc.so.6")
    >
    > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490>>>> cdll.LoadLibrary("libucdb.so")
    >
    > Traceback (most recent call last):
    >   File "<stdin>", line 1, in <module>
    >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > lib/pyth=
    > on2.5/ctypes/__init__.py", line 423, in LoadLibrary
    >     return self._dlltype(name)
    >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > lib/pyth=
    > on2.5/ctypes/__init__.py", line 340, in __init__
    >     self._handle =3D _dlopen(self._name, mode)
    > OSError: libucdb.so: cannot open shared object file: No such file or
    > directo=
    > ry>>> cdll.LoadLibrary("libc.so.6")
    >
    > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95df3ad0>>>> libc =3D CDLL("libc.so.6")
    > >>> libc

    >
    > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490>>>> libc =3D CDLL("libucdb.so")
    >
    > Traceback (most recent call last):
    >   File "<stdin>", line 1, in <module>
    >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > lib/pyth=
    > on2.5/ctypes/__init__.py", line 340, in __init__
    >     self._handle =3D _dlopen(self._name, mode)
    > OSError: libucdb.so: cannot open shared object file: No such file or
    > directo=
    > ry>>> libc =3D CDLL("/opt/questasim_6.4/questasim/linux/libucdb.so")
    >
    > Traceback (most recent call last):
    >   File "<stdin>", line 1, in <module>
    >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > lib/pyth=
    > on2.5/ctypes/__init__.py", line 340, in __init__
    >     self._handle =3D _dlopen(self._name, mode)
    > OSError: /opt/questasim_6.4/questasim/linux/libucdb.so: cannot open
    > shared o=
    > bject file: No such file or directory>>> ^[[A
    >
    >   File "<stdin>", line 1
    >     ^
    > SyntaxError: invalid syntax
    >
    >
    >
    > - Paddy.


    Any help would be appreciated.

    Thanks.
     
    Paddy, Aug 27, 2008
    #2
    1. Advertising

  3. Paddy

    castironpi Guest

    On Aug 27, 12:03 am, Paddy <> wrote:
    > On Aug 23, 2:33 pm, Paddy <> wrote:
    > > Hi,
    > > I am am falling at the first hurdle when trying to access a library
    > > using ctypes.

    >
    > > I have a file libucdb.so which the file command says is shared object,
    > > but I cannot get it to load:

    >
    > > Any help would be appreciated:

    >
    > > dmccarthy: file /opt/questasim_6.4/questasim/linux/libucdb.a /opt/
    > > questasim_=
    > > 6.4/questasim/linux/libucdb.so
    > > /opt/questasim_6.4/questasim/linux/libucdb.a:  current ar archive
    > > /opt/questasim_6.4/questasim/linux/libucdb.so: ELF 32-bit LSB shared
    > > object,=
    > >  Intel 80386, version 1 (SYSV), not stripped
    > > dmccarthy: python
    > > ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
    > > Python 2.5.1 (r251:54863, May  2 2007, 08:46:07)
    > > [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
    > > Type "help", "copyright", "credits" or "license" for more information.>>> cdll.LoadLibrary("libc.so.6")

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > > NameError: name 'cdll' is not defined>>> from ctypes import *
    > > >>> ^[[A^[[A

    >
    > >     ^e "<stdin>", line 1
    > > SyntaxError: invalid syntax>>> cdll.LoadLibrary("libc.so.6")

    >
    > > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490>>>> cdll.LoadLibrary("libucdb.so")

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > > lib/pyth=
    > > on2.5/ctypes/__init__.py", line 423, in LoadLibrary
    > >     return self._dlltype(name)
    > >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > > lib/pyth=
    > > on2.5/ctypes/__init__.py", line 340, in __init__
    > >     self._handle =3D _dlopen(self._name, mode)
    > > OSError: libucdb.so: cannot open shared object file: No such file or
    > > directo=
    > > ry>>> cdll.LoadLibrary("libc.so.6")

    >
    > > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95df3ad0>>>> libc =3D CDLL("libc.so.6")
    > > >>> libc

    >
    > > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490>>>> libc =3D CDLL("libucdb.so")

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > > lib/pyth=
    > > on2.5/ctypes/__init__.py", line 340, in __init__
    > >     self._handle =3D _dlopen(self._name, mode)
    > > OSError: libucdb.so: cannot open shared object file: No such file or
    > > directo=
    > > ry>>> libc =3D CDLL("/opt/questasim_6.4/questasim/linux/libucdb.so")


    Try 'open( "libucdb.so", "rb" )' to see if you're looking in the right
    place.
     
    castironpi, Aug 27, 2008
    #3
  4. Paddy

    Uwe Schmitt Guest

    On 27 Aug., 07:03, Paddy <> wrote:
    > On Aug 23, 2:33 pm, Paddy <> wrote:
    >
    >
    >
    > > Hi,
    > > I am am falling at the first hurdle when trying to access a library
    > > using ctypes.

    >
    > > I have a file libucdb.so which the file command says is shared object,
    > > but I cannot get it to load:

    >
    > > Any help would be appreciated:

    >
    > > dmccarthy: file /opt/questasim_6.4/questasim/linux/libucdb.a /opt/
    > > questasim_=
    > > 6.4/questasim/linux/libucdb.so
    > > /opt/questasim_6.4/questasim/linux/libucdb.a:  current ar archive
    > > /opt/questasim_6.4/questasim/linux/libucdb.so: ELF 32-bit LSB shared
    > > object,=
    > >  Intel 80386, version 1 (SYSV), not stripped
    > > dmccarthy: python
    > > ActivePython 2.5.1.1 (ActiveState Software Inc.) based on
    > > Python 2.5.1 (r251:54863, May  2 2007, 08:46:07)
    > > [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
    > > Type "help", "copyright", "credits" or "license" for more information.>>> cdll.LoadLibrary("libc.so.6")

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > > NameError: name 'cdll' is not defined>>> from ctypes import *
    > > >>> ^[[A^[[A

    >
    > >     ^e "<stdin>", line 1
    > > SyntaxError: invalid syntax>>> cdll.LoadLibrary("libc.so.6")

    >
    > > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490>>>> cdll.LoadLibrary("libucdb.so")

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > > lib/pyth=
    > > on2.5/ctypes/__init__.py", line 423, in LoadLibrary
    > >     return self._dlltype(name)
    > >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > > lib/pyth=
    > > on2.5/ctypes/__init__.py", line 340, in __init__
    > >     self._handle =3D _dlopen(self._name, mode)
    > > OSError: libucdb.so: cannot open shared object file: No such file or
    > > directo=
    > > ry>>> cdll.LoadLibrary("libc.so.6")

    >
    > > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95df3ad0>>>> libc =3D CDLL("libc.so.6")
    > > >>> libc

    >
    > > <CDLL 'libc.so.6', handle 2a958a2900 at 2a95dda490>>>> libc =3D CDLL("libucdb.so")

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > > lib/pyth=
    > > on2.5/ctypes/__init__.py", line 340, in __init__
    > >     self._handle =3D _dlopen(self._name, mode)
    > > OSError: libucdb.so: cannot open shared object file: No such file or
    > > directo=
    > > ry>>> libc =3D CDLL("/opt/questasim_6.4/questasim/linux/libucdb.so")

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > >   File "/software/unix-soft/linux/ActivePython-2.5.1.1-linux-x86_64/
    > > lib/pyth=
    > > on2.5/ctypes/__init__.py", line 340, in __init__
    > >     self._handle =3D _dlopen(self._name, mode)
    > > OSError: /opt/questasim_6.4/questasim/linux/libucdb.so: cannot open
    > > shared o=
    > > bject file: No such file or directory>>> ^[[A

    >
    > >   File "<stdin>", line 1
    > >     ^
    > > SyntaxError: invalid syntax

    >
    > > - Paddy.

    >
    > Any help would be appreciated.
    >
    > Thanks.


    What is your current working directory and where is the lib located ?
    Maybe the lib is not in your working directory.

    If you want the lib accessed from anywhere, you have to copy it
    to /usr/lib or /usr/local/lib.
    Another possibility is setting LD_LIBRARY_PATH.

    Greetings, Uwe
     
    Uwe Schmitt, Aug 27, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henk Punt
    Replies:
    0
    Views:
    403
    Henk Punt
    Jul 23, 2004
  2. Ernesto

    Ctypes Install in Linux

    Ernesto, Sep 12, 2005, in forum: Python
    Replies:
    4
    Views:
    1,021
    Ernesto
    Sep 13, 2005
  3. subopt inTheVicinityOf geemail.com

    Trouble loading dll via ctypes

    subopt inTheVicinityOf geemail.com, Jan 29, 2008, in forum: Python
    Replies:
    1
    Views:
    352
    Helmut Jarausch
    Jan 30, 2008
  4. Replies:
    0
    Views:
    506
  5. Tim Grove

    ctypes - loading 'librsvg-2-2.dll'

    Tim Grove, Aug 26, 2008, in forum: Python
    Replies:
    0
    Views:
    430
    Tim Grove
    Aug 26, 2008
Loading...

Share This Page