我试着在 StackOverflow 上问这个问题,但随之而来的死寂让我想知道是否可能需要更多 Ubuntu 特定的专业知识。
我正在尝试构建一个静态版本的 Python:
./configure --disable-shared LDFLAGS="-static -static-libgcc" CPPFLAGS="-static"
Run Code Online (Sandbox Code Playgroud)
但是,运行make如上配置最终会产生一些警告和错误:
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
Run Code Online (Sandbox Code Playgroud)
我被困住了。它似乎要求我重新编译 libc。我认为-static-libgcc这就足够了,但显然不是。我不知道链接的 libc 是否有问题,或者我的编译标志是否有问题。这使得它很难继续。有谁知道这里发生了什么,以及如何实现我在 Ubuntu 11.04 上构建静态 python 的目标?
小智 5
为了只构建python二进制文件,在您的步骤(上述错误)之后,您可以手动运行
gcc -pthread -static -static-libgcc -o python Modules/python.o libpython3.2m.a -lpthread -ldl -lutil -lm
Run Code Online (Sandbox Code Playgroud)
差异-Xlinker -export-dynamic正在消除。
但是我没有测试该二进制文件的实际使用情况(只是运行它并运行)。
如果你想使用真正的静态构建,你将不得不使用不同的 C 库。
Glibc 不会为你解决这个问题,如果你想静态链接,你必须寻找运行时可能需要的所有内容的 *.a 版本,并将它们全部放入应用程序中。如果环境发生变化,您的应用程序将会崩溃。通常动态库会处理这个问题,因此它们是首选。
据我所知,没有适合你的解决方案。
| 归档时间: |
|
| 查看次数: |
8491 次 |
| 最近记录: |