Build Question: How to Add -Wl, --option Before Objects In

Ned Deily nad at
Mon Oct 27 21:39:32 CET 2014

In article 
<CAHu5PrbHSob2r-zOTCtrYiqdudU_q+4mDXOXzp=_ReJp7khTDg at>,
 Cyd Haselton <chaselton at> wrote:
> I need to add a linker option to the command(s) run by when
> building various objects.  I'm not familiar with Python at all, so I
> basically copied and modified a line from one area of the script to
> another
> ext_modules=[Extension('_struct', ['_struct.c'], extra_link_args =
> ['Wl,--allow-shlib-undefined'])],
>                      *snip*
> Unfortunately this seems to append the option to the end of the
> command line.  What's the best (fastest) way to add it before the
> object being built (objectname.o)?

It depends on what system and build tools that you are using and that 
the Python you are using was built with but, in general on most 
POSIX-like systems, one way to do it should be to supply it via an 
LDFLAGS environment variable.  The safest approach would be to get the 
default value of LDFLAGS for this Python instance, append your 
additional values to it, and pass it back into the build.  You 
can do that all in one line:

LDFLAGS="$(python -c 'import 
-Wl,--allow-shlib-undefined" python build

 Ned Deily,
 nad at

More information about the Python-list mailing list