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


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.

  • Can you define real static build? Seeing as others have built static versions of Python, I am prone to believe it can be done. – Adoring Gumdrop Sep 30 '11 at 14:45
  • Then you should use the option provided on the posts: bytes.com/topic/python/answers/…, I think its just too much work and depending on what you want it will be so tedious that it can't be done in normal circumstances. Just saying, if you want to go ahead there is nothing I can say that will add or remove anything to the comments on those posts. – Bruno Pereira Sep 30 '11 at 15:04
  • That very post is the one were people are reporting successfully compiling a static python. I am posting this question because the same steps does not seem to work for me. – Adoring Gumdrop Sep 30 '11 at 16:30
  • Well in my idea loading initgroups requires you to load other parts of glibc maybe that is your problem. It may work on other builds but not working with yours. Why do you want to build this static anyways? – Bruno Pereira Sep 30 '11 at 18:41
  • Even when I comment out all the modules that cause Using 'foo' in statically linked applications... warnings, I still get the linker error. And I want to build static to get a similar environment to when I later port the project to iOS, and additionally I want to understand the problem better. – Adoring Gumdrop Sep 30 '11 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.