Re: Static Linking...

Ronald Oussoren <[email protected]>
Newsgroups gmane.comp.python.apple
Message-ID <[email protected]>
On 24 May, 2013, at 1:41, Chris Barker - NOAA Federal <[email protected]> wrote:

> As a side note to the main thread about dependencies:
> 
> How can  I static link?

It is a lot easier when there is only a static archive in a directory and no dylib (that is build libpng with --enable-static --disable-shared). In recent version of the devtools that should be good enough. When building with older Xcodes (before 4.0) you have to add '-Wl,-search_paths_first' to the link flags to ensure that the .a file will be used even when there is a .dylib futher on in the search path used by the linker (this must be used when static linking ncurses because there is a dylib for ncurses in the default search path).

I haven't found a way yet to make the linker prefer static libraries ("cc -static" does something different than it does on Linux and cannot be used to build normal binaries), at least not beyond the trick you mention later on.

> 
> I"ve struggled for literally years to get gcc to statically link, but
> it tries really hard to dynamically link instead. I have written way
> too many scripts that move or re-name dynamic libs temporarily while
> building, then put them back after.
> 
> Then a colleague of mine showed me the really neat trick -- pass the
> paths to the libs themselves through to gcc with "extra_objects"
> keyword in the Extension object, like so:
> 
> extra_objects = ["libhdf5.a", "libhdf5_hl.a", "libnetcdf.a"]
> 
> extensions = [Extension("netCDF4",
>                        sources,
>                        libraries=libs,
>                        include_dirs=inc_dirs,
>                        extra_objects=extra_objects,
>                        )]
> 
> very nifty -- works like a charm.
> 
> However, when I do this, I had to re-write part of the setup.py --
> actually, making it far more simple -- in this case, there was a lot
> of machinations finding the libs...
> 
> But Ideally, I"d ;like to build a semi-arbitrary extension with static
> linking while using the existing setup.py. Is there a way to
> minkey-path the setup, so I can use the existing one, but re-shuffle
> it some in place before the actual build occurs?

Not that I know, beyond assuring that static libraries are in a different directory than dylibs. That's not very hard to arrange, but it annoying work that shouldn't be necessary...

Ronald

_______________________________________________
Pythonmac-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.