[Numpy-discussion] New to ctypes. Some problems with loading shared library.

Ryan May rmay@ou....
Tue Feb 5 10:34:47 CST 2008

Lou Pecora wrote:
> I got ctypes installed and passing its own tests.  But
> I cannot get the shared library to load.  I am using
> Mac OS X 10.4.11, Python 2.4 running through the
> Terminal.
> I am using Albert Strasheim's example on
> http://scipy.org/Cookbook/Ctypes2 except that I had to
> remove the defined 'extern' for FOO_API since the gcc
> compiler complained about two 'externs' (I don't
> really understand what the extern does here anyway). 
> My make file for generating the library is simple,
> # ---- Link ---------------------------
> test1ctypes.so:  test1ctypes.o  test1ctypes.mak
> 	gcc -bundle -flat_namespace -undefined suppress -o
> test1ctypes.so  test1ctypes.o
> # ---- gcc C compile ------------------
> test1ctypes.o:  test1ctypes.c test1ctypes.h
> test1ctypes.mak
> 	gcc -c test1ctypes.c -o test1ctypes.o
> This generates the file test1ctypes.so.  But when I
> try to load it
> import numpy as N
> import ctypes as C
> _test1 = N.ctypeslib.load_library('test1ctypes', '.')
> I get the error message,
> OSError: dlopen(/Users/loupecora/test1ctypes.dylib,
> 6): image not found
> I've been googling for two hours trying to find the
> problem or other examples that would give me a clue,
> but no luck.  
> Any ideas what I'm doing wrong?  Thanks for any clues.
Well, it's looking for test1ctypes.dylib, which I guess is a MacOSX
shared library?  Meanwhile, you made a test1ctypes.so, which is why it
can't find it.  You could try using this instead:

_test1 = N.ctypeslib.load_library('test1ctypes.so', '.')

or try to get gcc to make a test1ctypes.dylib.


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

More information about the Numpy-discussion mailing list