Hi,
We need a static Python build. See the build flags below, but somehow the -shared
flag keep being present in the gcc commands. Could somebody please please help us with our static python build getting working?
I’m aware I most likely also need to build openssl and libffi in a static manner. But let’s try to tackle the problem one by one.
We use a Ubuntu 20.04 LTS Docker image. And we try to build the latest version (3.12.2) from source at this moment in time.
This is the configure command:
./configure \
--enable-optimizations \
--with-ensurepip=install \
--prefix="$rollout" \
--disable-shared \
--with-static-libpython \
LDFLAGS="-static -static-libgcc" \
CFLAGS="-static" \
CPPFLAGS="-static" \
CFLAGSFORSHARED="" CCSHARED="" LDSHARED="" LDCXXSHARED="" \
MODULE_BUILDTYPE=static
Then I also added *static*
for the Python modules (to this special Setup.local file):
echo "*static*" >> Modules/Setup.local
And finally the make command itself:
make LINKFORSHARED=" " CCSHARED="" LDSHARED="" LDCXXSHARED="" -j 10
Now the gcc command will have -static
flag but also still the -shared
flag!? How to get rid of this -shared
flag:
gcc -pthread -shared -static -static-libgcc -fno-semantic-interposition -fprofile-generate Modules/_testimportmultiple.o -o Modules/_testimportmultiple.cpython-312-x86_64-linux-gnu.so
gcc -pthread -shared -static -static-libgcc -fno-semantic-interposition -fprofile-generate Modules/_testsinglephase.o -o Modules/_testsinglephase.cpython-312-x86_64-linux-gnu.so
gcc -pthread -shared -static -static-libgcc -fno-semantic-interposition -fprofile-generate Modules/xxlimited.o -o Modules/xxlimited.cpython-312-x86_64-linux-gnu.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
/usr/bin/ld: Modules/_testimportmultiple.o: relocation R_X86_64_PC32 against symbol `PyInit__testimportmultiple_bar' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
What do I wrong? Why has the gcc commands still -shared
in the commands? Thanks in advance.
Ps. And no you don’t want to add -fPIC
, since that is used for shared libs only.
Ps. Ps. Some commands seems fine like: gcc -pthread -fno-strict-overflow -DNDEBUG -g -O3 -Wall -static -fno-semantic-interposition -std=c11 -Werror=implicit-function-declaration -fvisibility=hidden -fprofile-generate -I./Include/internal -I. -I./Include -static -DPy_BUILD_CORE_BUILTIN -c ./Modules/itertoolsmodule.c -o Modules/itertoolsmodule.o
. But then later it swiches to modules and it fails:
rm -f Modules/_hacl/libHacl_Hash_SHA2.a
rm -f Modules/expat/libexpat.a
ar rcs Modules/_hacl/libHacl_Hash_SHA2.a Modules/_hacl/Hacl_Hash_SHA2.o
ar rcs Modules/expat/libexpat.a Modules/expat/xmlparse.o Modules/expat/xmlrole.o Modules/expat/xmltok.o
gcc -pthread -shared -static -static-libgcc -fno-semantic-interposition -fprofile-generate Modules/_testimportmultiple.o -o Modules/_testimportmultiple.cpython-312-x86_64-linux-gnu.so
gcc -pthread -shared -static -static-libgcc -fno-semantic-interposition -fprofile-generate Modules/_testsinglephase.o -o Modules/_testsinglephase.cpython-312-x86_64-linux-gnu.so
gcc -pthread -shared -static -static-libgcc -fno-semantic-interposition -fprofile-generate Modules/xxlimited.o -o Modules/xxlimited.cpython-312-x86_64-linux-gnu.so
gcc -pthread -shared -static -static-libgcc -fno-semantic-interposition -fprofile-generate Modules/xxlimited_35.o -o Modules/xxlimited_35.cpython-312-x86_64-linux-gnu.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
Regards,
Melroy van den Berg