Differences between revisions 5 and 6
Revision 5 as of 2016-08-27 08:22:20
Size: 1653
Comment: Add a link which covers building python statically.
Revision 6 as of 2016-08-28 04:14:20
Size: 1578
Comment: Rewrite, add notes for building python statically, add example for building in modules - tested with Python 3.5.2, although I'm adding a few extra flags which should not matter
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

/!\ '''This page is a placeholder until MicahElliott (or anyone) figures out all the steps to make this work.'''
Line 8: Line 6:
$ ldd /path/to/bin/python $ ldd /path/to/python
Line 12: Line 10:
{i} Note that the `--disable-shared` option is not related to building Python statically.

There is a file called `Modules/Setup.local` which is designed for customizing how modules are built.

GCC (and LD) offer a `-static` option to create static executables.

It would be nice to have a `--enable-all-static` option in the `configure` script which would take care of all this for you. For an example, try building [[http://subversion.tigris.org|Subversion]].

See http://mdqinc.com/blog/2011/08/statically-linking-python-with-cython-generated-modules-and-packages/ for a detailed example which includes both how to build a barebones static python, and adding custom modules to the binary.

== Static Modules Built Into libpythonX.X.a ==

Haven't figured out how to make {{{python}}} static, but here is how to make all of the modules static.
Building the python binary is fairly straightforward:
Line 27: Line 13:
./configure $ ./configure LDFLAGS=”-static” --disable-shared
$ make LDFLAGS=”-static” LINKFORSHARED=” ”
Line 30: Line 17:
Edit Modules/Setup.local and add the line: 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
Line 36: Line 26:
then... followed by any of the modules that you want to build into your python binary.
For instance, if you wanted to build in the math library, add
Line 39: Line 30:
./configure
make
make install
math mathmodule.c _math.c # -lm # math library functions, e.g. sin()
Line 44: Line 33:
For the full answer see http://stackoverflow.com/questions/1150373/compile-the-python-interpreter-statically Note that the line is not commented (unlike the corresponding line in Modules/Setup.dist).
See Modules/Setup.dist for more 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/

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. 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.dist). See Modules/Setup.dist for more examples and documentation.

See also

BuildStatically (last edited 2021-03-29 18:21:47 by WilliamWoodruff)

Unable to edit the page? See the FrontPage for instructions.