Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Building Python statically on linux

3,753 views
Skip to first unread message

Micah Elliott

unread,
Dec 27, 2007, 10:53:57 AM12/27/07
to
Are there instructions somewhere on how to build Python (on linux)
statically? This seems like a common thing to do want to do, but my
searching isn't turning up much. If it is common, it would be nice to
see a configure option like I've seen in other tools:

--enable-all-static Build completely static (standalone)
binaries.

I'm ./configure-ing with "--disable-shared" (because this must mean
"enable static", right?), and (based on some other posts here) tried
adding "*static*" near the top of Modules/Setup. I'd like to see ldd
tell me "not a dynamic executable", but alas, it's presently:

$ ldd /path/to/new/bin/python
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x008e9000)
libdl.so.2 => /lib/libdl.so.2 (0x007f0000)
libutil.so.1 => /lib/libutil.so.1 (0x00df6000)
libm.so.6 => /lib/tls/libm.so.6 (0x007cb000)
libc.so.6 => /lib/tls/libc.so.6 (0x0069f000)
/lib/ld-linux.so.2 (0x00682000)

Do I just need to be passing something like LDFLAGS="-static ???" to
configure? I just tried that and got a bunch of "symbol rename"
warnings during the compilation, and then "make install" mysteriously
failed.

Thanks for any pointers.
--
Micah

Christian Heimes

unread,
Dec 27, 2007, 11:21:21 AM12/27/07
to pytho...@python.org
Micah Elliott wrote:
> I'm ./configure-ing with "--disable-shared" (because this must mean
> "enable static", right?), and (based on some other posts here) tried
> adding "*static*" near the top of Modules/Setup. I'd like to see ldd
> tell me "not a dynamic executable", but alas, it's presently:

--disabled-shared is the default value. It does not mean that the Python
interpreter is a static linked executable. --enable-shared builds a
libpython??.so and --disable-shared links libpython into the python binary.

Christian

Zentrader

unread,
Dec 27, 2007, 11:32:41 AM12/27/07
to
On Dec 27, 8:21 am, Christian Heimes <li...@cheimes.de> wrote:
> Micah Elliott wrote:
> > I'm ./configure-ing with "--disable-shared" (because this must mean
> > "enable static", right?)

I think you can just add -static to the gcc Flag line in the
makefile. "man gcc" should also be helpful but that is a pile of docs
to wade through.

Micah Elliott

unread,
Dec 27, 2007, 4:29:09 PM12/27/07
to
On Dec 27, 8:32 am, Zentrader <zentrad...@gmail.com> wrote:

> I think you can just add -static to the gcc Flag line in the
> makefile.

Doing that (or CFLAGS=-static, or LDFLAGS=-static, or other Makefile
tweaks) gets me linker errors. Sounds like there's not a simple
prescribed means to do this (that anyone has documented). So now I'm
open to hearing about other hacks people have done to get this to
work. (Hopefully a config weenie heard my plea for --enable-all-
static)

--
Micah

Christian Heimes

unread,
Dec 28, 2007, 8:44:56 AM12/28/07
to Micah Elliott, pytho...@python.org
Micah Elliott wrote:
> Doing that (or CFLAGS=-static, or LDFLAGS=-static, or other Makefile
> tweaks) gets me linker errors. Sounds like there's not a simple
> prescribed means to do this (that anyone has documented). So now I'm
> open to hearing about other hacks people have done to get this to
> work. (Hopefully a config weenie heard my plea for --enable-all-
> static)

Can you work on the topic and write a small howto for your wiki
(http://wiki.python.org/moin/)? You have to modify Modules/Setup.local,
too. Read Modules/Setup for more information.

Christian

Christian Heimes

unread,
Dec 28, 2007, 8:44:56 AM12/28/07
to pytho...@python.org, pytho...@python.org
Micah Elliott wrote:
> Doing that (or CFLAGS=-static, or LDFLAGS=-static, or other Makefile
> tweaks) gets me linker errors. Sounds like there's not a simple
> prescribed means to do this (that anyone has documented). So now I'm
> open to hearing about other hacks people have done to get this to
> work. (Hopefully a config weenie heard my plea for --enable-all-
> static)

Can you work on the topic and write a small howto for your wiki

Micah Elliott

unread,
Dec 28, 2007, 12:01:40 PM12/28/07
to
On Dec 28, 5:44 am, Christian Heimes <li...@cheimes.de> wrote:

> Can you work on the topic and write a small howto for your wiki
> (http://wiki.python.org/moin/)?

Good idea. I've created a placeholder (with what I know so far, not
much) to track this:

http://wiki.python.org/moin/BuildStatically

I'll plan to be updating it today if I can get it working. Anyone
else is welcome to add their knowledge/experience.

0 new messages