[Numpy-discussion] New to ctypes. Some problems with loading shared library.
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. -- Lou Pecora, my views are my own. Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] New to ctypes. Some problems with loading shared library.
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 -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] New to ctypes. Some problems with loading shared library.
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 Thanks, Ryan. You were on the right track. I changed the name of the file in the load_library call to test1ctypes.so and I had to put in the full path to the file as the second argument. The default path was to my home directory. I could probably change paths with a python os call, too. Anyway, IT WORKED! How 'bout that? One simple example down and now on to more complex things. Thanks, again. -- Lou Pecora, my views are my own. Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion