I am trying to make a static build of Python. This is so that I can get the build to work on multiple Linux platforms. I am trying to build on Rocky 8.
I think that I have successfully built the python interpreter itself:
# ldd /usr/local/bin/python3
not a dynamic executable
# /usr/local/bin/python3 -V
Python 3.10.16
My original configure and make commands were:
./configure LDFLAGS="--static" --disable-shared
make LDFLAGS="--static" LINKFORSHARED=" "
make install
However, pip (pip3) doesn’t work. It complains about a missing module “msvcrt”:
# /usr/local/bin/pip3 install fusesoc
Traceback (most recent call last):
File "/usr/local/lib/python3.10/subprocess.py", line 69, in <module>
import msvcrt
ModuleNotFoundError: No module named 'msvcrt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/main_parser.py", line 5, in <module>
import subprocess
File "/usr/local/lib/python3.10/subprocess.py", line 74, in <module>
import _posixsubprocess
ImportError: /usr/local/lib/python3.10/lib-dynload/_posixsubprocess.cpython-310-x86_64-linux-gnu.so: undefined symbol: PyTuple_Type
I don’t think that I need pip to be statically built (once I install fusesoc, then I can bundle everything).
I put “msvcrt” in the file Modules/Setup.local and ran make again, but got the following:
# make
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE \
-DABIFLAGS='""' \
-DMULTIARCH=\"x86_64-linux-gnu\" \
-o Python/sysmodule.o ./Python/sysmodule.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE \
-DSOABI='"cpython-310-x86_64-linux-gnu"' \
-o Python/dynload_shlib.o ./Python/dynload_shlib.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Modules/config.o Modules/config.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -DPYTHONPATH='""' \
-DPREFIX='"/usr/local"' \
-DEXEC_PREFIX='"/usr/local"' \
-DVERSION='"3.10"' \
-DVPATH='""' \
-o Modules/getpath.o ./Modules/getpath.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden -I./Include/internal -I. -I./Include -DPy_BUILD_CORE \
-DGITVERSION="\"`LC_ALL=C `\"" \
-DGITTAG="\"`LC_ALL=C `\"" \
-DGITBRANCH="\"`LC_ALL=C `\"" \
-o Modules/getbuildinfo.o ./Modules/getbuildinfo.c
rm -f libpython3.10.a
ar rcs libpython3.10.a Modules/getbuildinfo.o Parser/token.o Parser/pegen.o Parser/parser.o Parser/string_parser.o Parser/peg_api.o Parser/myreadline.o Parser/tokenizer.o Objects/abstract.o Objects/accu.o Objects/boolobject.o Objects/bytes_methods.o Objects/bytearrayobject.o Objects/bytesobject.o Objects/call.o Objects/capsule.o Objects/cellobject.o Objects/classobject.o Objects/codeobject.o Objects/complexobject.o Objects/descrobject.o Objects/enumobject.o Objects/exceptions.o Objects/genericaliasobject.o Objects/genobject.o Objects/fileobject.o Objects/floatobject.o Objects/frameobject.o Objects/funcobject.o Objects/interpreteridobject.o Objects/iterobject.o Objects/listobject.o Objects/longobject.o Objects/dictobject.o Objects/odictobject.o Objects/memoryobject.o Objects/methodobject.o Objects/moduleobject.o Objects/namespaceobject.o Objects/object.o Objects/obmalloc.o Objects/picklebufobject.o Objects/rangeobject.o Objects/setobject.o Objects/sliceobject.o Objects/structseq.o Objects/tupleobject.o Objects/typeobject.o Objects/unicodeobject.o Objects/unicodectype.o Objects/unionobject.o Objects/weakrefobject.o Python/_warnings.o Python/Python-ast.o Python/asdl.o Python/ast.o Python/ast_opt.o Python/ast_unparse.o Python/bltinmodule.o Python/ceval.o Python/codecs.o Python/compile.o Python/context.o Python/dynamic_annotations.o Python/errors.o Python/frozenmain.o Python/future.o Python/getargs.o Python/getcompiler.o Python/getcopyright.o Python/getplatform.o Python/getversion.o Python/hamt.o Python/hashtable.o Python/import.o Python/importdl.o Python/initconfig.o Python/marshal.o Python/modsupport.o Python/mysnprintf.o Python/mystrtoul.o Python/pathconfig.o Python/preconfig.o Python/pyarena.o Python/pyctype.o Python/pyfpe.o Python/pyhash.o Python/pylifecycle.o Python/pymath.o Python/pystate.o Python/pythonrun.o Python/pytime.o Python/bootstrap_hash.o Python/structmember.o Python/symtable.o Python/sysmodule.o Python/thread.o Python/traceback.o Python/getopt.o Python/pystrcmp.o Python/pystrtod.o Python/pystrhex.o Python/dtoa.o Python/formatter_unicode.o Python/fileutils.o Python/suggestions.o Python/dynload_shlib.o Modules/config.o Modules/getpath.o Modules/main.o Modules/gcmodule.o Modules/posixmodule.o Modules/errnomodule.o Modules/pwdmodule.o Modules/_sre.o Modules/_codecsmodule.o Modules/_weakref.o Modules/_functoolsmodule.o Modules/_operator.o Modules/_collectionsmodule.o Modules/_abc.o Modules/itertoolsmodule.o Modules/atexitmodule.o Modules/signalmodule.o Modules/_stat.o Modules/timemodule.o Modules/_threadmodule.o Modules/_localemodule.o Modules/_iomodule.o Modules/iobase.o Modules/fileio.o Modules/bytesio.o Modules/bufferedio.o Modules/textio.o Modules/stringio.o Modules/faulthandler.o Modules/_tracemalloc.o Modules/symtablemodule.o Modules/xxsubtype.o Python/frozen.o
gcc -pthread --static -Xlinker -export-dynamic -o python Programs/python.o libpython3.10.a -lcrypt -lpthread -ldl -lutil -lm -lm
libpython3.10.a(dynload_shlib.o): In function `_PyImport_FindSharedFuncptr':
/tmp/docker_tmp/Python-3.10.16/./Python/dynload_shlib.c:100: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libpython3.10.a(posixmodule.o): In function `os_getgrouplist_impl':
/tmp/docker_tmp/Python-3.10.16/./Modules/posixmodule.c:7548: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libpython3.10.a(posixmodule.o): In function `os_initgroups_impl':
/tmp/docker_tmp/Python-3.10.16/./Modules/posixmodule.c:7747: warning: Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libpython3.10.a(pwdmodule.o): In function `pwd_getpwall_impl':
/tmp/docker_tmp/Python-3.10.16/./Modules/pwdmodule.c:300: warning: Using 'getpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/docker_tmp/Python-3.10.16/./Modules/pwdmodule.c:299: warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/docker_tmp/Python-3.10.16/./Modules/pwdmodule.c:310: warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libpython3.10.a(pwdmodule.o): In function `pwd_getpwnam_impl':
/tmp/docker_tmp/Python-3.10.16/./Modules/pwdmodule.c:247: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libpython3.10.a(pwdmodule.o): In function `pwd_getpwuid':
/tmp/docker_tmp/Python-3.10.16/./Modules/pwdmodule.c:164: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libpython3.10.a(config.o):(.data+0x8): undefined reference to `PyInit_msvcrt'
collect2: error: ld returned 1 exit status
make: *** [Makefile:601: python] Error 1
I saved the stdout and stderr from re-running configure and it shows that it doesn’t think it is cross-compiling:
checking host system type... x86_64-pc-linux-gnu
checking for python3.10... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
Just in case it makes a difference, I am doing this in a Docker container, not a full OS.
Does this message mean that my static build won’t actually be portable to systems with a different version of glibc?
/tmp/docker_tmp/Python-3.10.16/./Python/dynload_shlib.c:100: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
I was curious, and spun up a VPS running Rocky. I could compile 3.14b on it, but not 3.10.16 at all, even without your options for a static build (just plain old ./configure and make -s -j 2):