GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Python Wiki
  • PSF Wiki
  • Jython Wiki
  • Python Wiki
  • Archive

This view

  • Original page
  • New address

GeezerVison is showing wiki.python.org — Build Statically

View as Markdown

Build Statically¶

Legacy Wiki Page

This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.

Building Python Statically¶

This page describes the steps required to build Python statically, derived from this thread. It presently covers Linux, but many of the same steps apply to other OSs. The goal is to get ldd to say:

$ ldd /path/to/python
not a dynamic executable

Building the python binary is fairly straightforward:

$ ./configure LDFLAGS="-static" --disable-shared
$ make LDFLAGS="-static" LINKFORSHARED=" "

LINKFORSHARED=" " prevents passing -export-dynamic to the linker, which will cause the binary to be built as a dynamically linked executable. You may need additional flags to build successfully.

This will build a static python binary, without any of the libraries normally provided by dynamically loaded modules. To add these modules, edit Modules/Setup.local, and add

*static*

followed by any of the modules that you want to build into your python binary. Any line in Modules/Setup.local with an “=” will be interpreted as a Makefile variable definition rather than a module. For instance, if you wanted to build in the math library, add

math mathmodule.c _math.c # -lm # math library functions, e.g. sin()

Note that the line is not commented (unlike the corresponding line in Modules/Setup). See Modules/Setup for guides on enabling other libraries, further examples and documentation.

See also¶

  • http://stackoverflow.com/questions/1150373/compile-the-python-interpreter-statically

  • http://mdqinc.com/blog/2011/08/statically-linking-python-with-cython-generated-modules-and-packages/

Previous
Build PyQt4 Windows
Next
Building Python with the free MS C Toolkit
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.