FAQ
Hi,

I know this is a pretty simple question but I've spent a while on this and
can't see whats wrong. I'm trying to access a shared library which I've
created called Simulation.so, its created as such (snip from makefile):

all: simulation

simulation: Simulation.so

Simulation.so: Simulation.o Statistics.o
gcc -shared Simulation.o Statistics.o -L/usr/local/lib -lsbml
-lstdc++ -lm -o Simulation.so

Statistics.o: Statistics.c Statistics.h
gcc -fpic -g -O2 -I/usr/include -c Statistics.c

Simulation.o: Simulation.c
gcc -fpic -g -O2 -I/usr/include -c Simulation.c

and I can load it properly in python

import ctypes
t = ctypes.CDLL('./Simulation.so')
this works fine, I have a simple function I ve put in for testing which just
returns the integer 4. However when I try to access this function it doesnt
work
t.test()
File "<stdin>", line 1, in <module>
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
line 325, in __getattr__
func = self.__getitem__(name)
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
line 330, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x81e6b0, test): symbol not found

I've tried using
t.__getattr__("test")
but still have the same exception, I've tried loading the library with mode
= RTLD_GLOBAL aswell and still have no luck. As far I as I can see this
should work? But as I am just starting with ctypes I am sure I doing
something sorry very stupid.

Any pointers would be greatly appreciated,

Many thanks in advance,

Nathan


Im hoping python-list is ok for questions regarding ctypes :S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-list/attachments/20080324/35ec7cc1/attachment-0001.htm

Search Discussions

  • Gabriel Genellina at Mar 25, 2008 at 1:26 am
    En Mon, 24 Mar 2008 19:56:08 -0300, Nathan Harmston
    <iwanttobeabadger at googlemail.com> escribi?:
    import ctypes
    t = ctypes.CDLL('./Simulation.so')
    this works fine, I have a simple function I ve put in for testing which
    just
    returns the integer 4. However when I try to access this function it
    doesnt
    work
    t.test()
    File "<stdin>", line 1, in <module>
    File
    "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
    line 325, in __getattr__
    func = self.__getitem__(name)
    File
    "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
    line 330, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
    AttributeError: dlsym(0x81e6b0, test): symbol not found
    Looks like the symbol isn't public - probably if you try loading the
    library with a C program it won't find it either. How is the function
    declared in the source?
    Try listing all public symbols with: nm -D Simulation.so
    Im hoping python-list is ok for questions regarding ctypes :S
    It's not off topic, although there is a specific list for ctypes-related
    questions. But hijacking a thread to post a completely different question
    is not good netiquette.

    --
    Gabriel Genellina
  • Nathan Harmston at Mar 25, 2008 at 1:58 am

    On 25/03/2008, Gabriel Genellina wrote:
    En Mon, 24 Mar 2008 19:56:08 -0300, Nathan Harmston
    <iwanttobeabadger at googlemail.com> escribi?:

    import ctypes
    t = ctypes.CDLL('./Simulation.so')
    this works fine, I have a simple function I ve put in for testing which
    just
    returns the integer 4. However when I try to access this function it
    doesnt
    work
    t.test()
    File "<stdin>", line 1, in <module>
    File
    "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
    line 325, in __getattr__
    func = self.__getitem__(name)
    File
    "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
    line 330, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
    AttributeError: dlsym(0x81e6b0, test): symbol not found

    Looks like the symbol isn't public - probably if you try loading the
    library with a C program it won't find it either. How is the function
    declared in the source?
    Try listing all public symbols with: nm -D Simulation.so
    Thanks for the quick reply:
    Running nm lists test as
    00001760 T _test

    in the source its declared as:

    int test(){
    return 4;
    }

    Sorry, this is the first time I'm making my own shared library and using
    ctypes, so being a little slow.

    Thanks again

    Nathan




    Im hoping python-list is ok for questions regarding ctypes :S


    It's not off topic, although there is a specific list for ctypes-related
    questions. But hijacking a thread to post a completely different question
    is not good netiquette.

    --
    Gabriel Genellina


    --
    http://mail.python.org/mailman/listinfo/python-list
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://mail.python.org/pipermail/python-list/attachments/20080325/1ed005ab/attachment.htm
  • Nathan Harmston at Mar 26, 2008 at 2:04 am
    Hi,

    Just as a follow up to this...I ve discovered that its an issue with
    building shared libraries on mac os and it works fine on a Linux box :S.

    Thanks

    Nathan
    On 25/03/2008, Nathan Harmston wrote:


    On 25/03/2008, Gabriel Genellina wrote:

    En Mon, 24 Mar 2008 19:56:08 -0300, Nathan Harmston
    <iwanttobeabadger at googlemail.com> escribi?:

    import ctypes
    t = ctypes.CDLL('./Simulation.so')
    this works fine, I have a simple function I ve put in for testing which
    just
    returns the integer 4. However when I try to access this function it
    doesnt
    work
    t.test()
    File "<stdin>", line 1, in <module>
    File
    "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
    line 325, in __getattr__
    func = self.__getitem__(name)
    File
    "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py",
    line 330, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
    AttributeError: dlsym(0x81e6b0, test): symbol not found

    Looks like the symbol isn't public - probably if you try loading the
    library with a C program it won't find it either. How is the function
    declared in the source?
    Try listing all public symbols with: nm -D Simulation.so
    Thanks for the quick reply:
    Running nm lists test as
    00001760 T _test

    in the source its declared as:

    int test(){
    return 4;
    }

    Sorry, this is the first time I'm making my own shared library and using
    ctypes, so being a little slow.

    Thanks again

    Nathan




    Im hoping python-list is ok for questions regarding ctypes :S


    It's not off topic, although there is a specific list for ctypes-related
    questions. But hijacking a thread to post a completely different
    question
    is not good netiquette.

    --
    Gabriel Genellina


    --
    http://mail.python.org/mailman/listinfo/python-list
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://mail.python.org/pipermail/python-list/attachments/20080326/857913bd/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 24, '08 at 10:56p
activeMar 26, '08 at 2:04a
posts4
users2
websitepython.org

People

Translate

site design / logo © 2022 Grokbase