7

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?

2 Answers2

5

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).

0xC0000022L
  • 5,870
sio4
  • 171
0

Well if you want to use a real static build you will have to use a different C library.

Glibc will not do the trick for you, if you want to statically link you must hunt down the *.a verions of everything that you could possibly need during runtime and put them all into the application. If the environment changes you application will break. Normally dynamic libraries will take care of that so they are preferred.

There is no solution for you as far as I know.

Bruno Pereira
  • 74,715