Building a static version of Python?
I tried asking this question at StackOverflow, but the dead silence that followed made me wonder if some more Ubuntu-specific expertise might be required.
I am trying to build a static version of Python thusly:
./configure --disable-shared LDFLAGS="-static -static-libgcc" CPPFLAGS="-static"
However, running make
configured as above eventually barfs up some warnings and an error:
gcc -pthread -static -static-libgcc -Xlinker -export-dynamic -o python \
Modules/python.o \
libpython2.7.a -lpthread -ldl -lutil -lm
<SNIP>
libpython2.7.a(posixmodule.o): In function `posix_initgroups':
Python-2.7.2/./Modules/posixmodule.c:3981: warning: Using 'initgroups' in
statically linked applications requires at runtime the shared
libraries from the glibc version used for linking
/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in
`/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/../../../libc.a(strcmp.o)'
can not be used when making an executable;
recompile with -fPIE and relink with -pie
collect2: ld returned 1 exit status
I'm stuck. It appears to be asking me to recompile libc. I thought -static-libgcc
would be enough, but apparently it is not. I don't know if there is something wrong with the libc being linked or if there is something wrong with my compilation flags. This makes it hard to proceed. Does anyone know what is going on here, and how to achieve my goal of building a static python on Ubuntu 11.04?
In order to just build the python
binary, after your step (above error), you can manually run
gcc -pthread -static -static-libgcc -o python Modules/python.o libpython3.2m.a -lpthread -ldl -lutil -lm
the difference is -Xlinker -export-dynamic
being removed.
But I did not test that binary for real use (just ran it and it runs).