[Distutils] static linking in distutils/setuptools?

Stefan Seefeld seefeld at sympatico.ca
Thu Jan 26 23:05:50 CET 2006

Robert Kern wrote:
> Christopher Fonnesbeck wrote:
>>Is there any way to specify static linking to particular libraries  when
>>building installers with distutils or setuptools? I want to be  able to
>>include the shared libraries that I am linking to in my  builds. I did
>>not see any info on this in the docs.
> Not really, no. In many cases (e.g., GNU ld), there's simply no way to tell the
> linker that you prefer static libraries to shared libraries when you are
> building a shared library like a Python extension. You simply have to make sure
> that the static libraries are found first.

I believe this is wrong. The (GNU ld) man pages mention '-Bdynamic' and '-Bstatic'
as a means to instruct the linker to link to a particular library dynamically or
statically. (To only link statically to libbar.a you could write e.g.

... -lfoo -Bstatic -lbar -Bdynamic -lbaz


However, the way distutils is written makes it practically impossible to control
such behavior without completely rewriting the whole 'build_ext' command.
Hopefully setuptools can manage this better.


More information about the Distutils-SIG mailing list