[Numpy-discussion] C Extensions, CTypes and "external code & libraries

David Cournapeau cournape@gmail....
Wed Feb 13 09:38:50 CST 2008

On Feb 14, 2008 12:14 AM, Lou Pecora <lou_boog2000@yahoo.com> wrote:
> --- David Cournapeau <david@ar.media.kyoto-u.ac.jp>
> wrote:
> > 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).
> [cut]
> David,
> 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.

Yes, I forgot that -shared does not work on mac os X. -Bstatic, being
a linker option as I said, had little chance to work on mac os X.  But
encouraged by your help, I got the

> # ---- Library make ---------------------------
> mysharedlib.so:  mysharedlib.o  mysharedlib.mak
>         gcc -bundle -flat_namespace -undefined suppress -o
> mysharedlib.so  mysharedlib.o \
>                 fcnlib.a
> # ---- gcc C compile ------------------
> mysharedlib.o:  mysharedlib.c mysharedlib.h
> mysharedlib.mak
>         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.

This is logical, or more exactly, the tools did what it thinks you are
asking: putting the archive (the .a library) in your executable. If
instead of libfnclib.a, you just put -lfcnlib in the command line, it
will pick up only the necessary code for the functions you are calling
(at least it does on linux if I remember correctly).

But the real question is : if you are concerned with code bload, why
using static lib at all ? Why not using shared library, which is
exactly designed to solve what you are trying to do ?



More information about the Numpy-discussion mailing list