Differences between revisions 7 and 8
Revision 7 as of 2017-10-16 14:17:44
Size: 1566
Editor: Wooble
Comment: smart quotes for shell commands aren't going to work...
Revision 8 as of 2021-03-29 18:21:47
Size: 1560
Comment: Updated paths, minor formatting fixes (use monospace for code fragments)
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
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. `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.
Line 33: Line 33:
Note that the line is not commented (unlike the corresponding line in Modules/Setup.dist).
See Modules/Setup.dist for more examples and documentation.
Note that the line is not commented (unlike the corresponding line in Modules/Setup).
See Modules/Setup for more examples and documentation.

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). See Modules/Setup 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.