[Numpy-discussion] C Extensions, CTypes and "external code & libraries"
Wed Feb 13 09:14:04 CST 2008
--- David Cournapeau <email@example.com>
> Oh, I may have misunderstood what you are trying to
> do then. You just
> want to call a shared library from another shared
> library ? This is
> possible on any platform supporting shared library
> (including but not
> limited to mac os x, windows, linux, most not
> ancient unices).
First, thanks very much for all the information. I am
still digesting it, but you gave a clear explanation
about the difference between shared and dynamic
libraries on the Mac.
I tried some of your compile/like commands, but the
Mac gcc did not understand some things like -Bstatic
and -shared. It seems to want to make bundles. I
guess your code was a Linux version which the Mac
doesn't like. But encouraged by your help, I got the
following make file to work:
# ---- Library make ---------------------------
mysharedlib.so: mysharedlib.o mysharedlib.mak
gcc -bundle -flat_namespace -undefined suppress -o
mysharedlib.so mysharedlib.o \
# ---- gcc C compile ------------------
mysharedlib.o: mysharedlib.c mysharedlib.h
gcc -c mysharedlib.c -o mysharedlib.o
In the above fcnlib.a is a simple static library I
made before using the above make. This created the
shared library mysharedlib.so which I imported and
handled with CTypes. Calling a function in fcnlib.a
from python worked.
A possible downside is that the shared library
contains *all* of the fcnlib. I examined it using "nm
mysharedlib.so". That showed that all the functions
of fcnlib.a were present in mysharedlib.so even though
the function in mysharedlib.c only called one function
of fcnlib.a. I don't know how much of a burden this
will impose at run time if do this with GSL. It would
be nice to only pick up the stuff I need. But at least
I have workable approach.
Thanks for your help. Comments welcome.
-- Lou Pecora, my views are my own.
Never miss a thing. Make Yahoo your home page.
More information about the Numpy-discussion