This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Failed to compile static python3.7.12
Type: compile error Stage: resolved
Components: Build Versions: Python 3.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: aprpp, ned.deily
Priority: normal Keywords:

Created on 2022-02-25 03:46 by aprpp, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
截图.PNG aprpp, 2022-02-25 03:46 compile error log
Setup.PNG aprpp, 2022-02-26 03:35 Modules/Setup Definition
Messages (9)
msg413958 - (view) Author: aprpp (aprpp) * Date: 2022-02-25 03:46
I compile static version of python3.7.12, I added the static standard library that I want to compile in Modules/Setup, reference Modules/Setup.dist in python source, like this:

static

Modules that should always be present (non UNIX dependent):
array arraymodule.c # array objects
cmath cmathmodule.c _math.c # -lm # complex math library functions
math mathmodule.c _math.c # -lm # math library functions, e.g. sin()
_contextvars _contextvarsmodule.c # Context Variables
_struct _struct.c # binary structure packing/unpacking

But there are still many modules that fail to compile, these modules with no commented out build definitions in the Modules/Setup.dist file. How do I add these modules build definitions to the Modules/Setup, yes they compile successfully ?

Failed to build these modules:
_bz2                  _ctypes               _ctypes_test
_decimal              _hashlib              _json
_lsprof               _lzma                 _multiprocessing
_opcode               _ssl                  _testbuffer
_testimportmultiple   _testmultiphase       _uuid
_xxtestfuzz           ossaudiodev           xxlimited
msg414054 - (view) Author: aprpp (aprpp) * Date: 2022-02-26 01:21
I  have signed the contributor agreement
msg414059 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2022-02-26 02:21
Successfully building a statically-linked version of Python depends greatly on the environment in which you are trying to build it and is really beyond the scope of this bug tracker. You don't say on which OS platform and version you are attempting this so it is hard to give any meaningful suggestions other than to make sure you have installed development versions (those including header files) of the various third-party libraries Python builds depend on (like libssl and libcrypto from OpenSSL), if your platform has a package manager, or build the required third-party libraries yourself. In any case, you will probably need to further edit the Setup file to reflect the location of the various third-party headers and libraries. As a rule, we don't do a lot of testing of static builds using Setup directly but some of the downstream distributors of Python do. Also note that Python 3.7 is now in the security-fix-only phase of its lifecycle prior to end-of-life in 2023, so further changes to the build process in 3.7 at this point would be out-of-scope. For what it's worth, there has been a significant amount of work in this area that is going into the next Python feature release, 3.11.0, planned for later this year so it should be significantly easier to do static builds and the like in 3.11. If you still run into problems with 3.7, suggest you ask in help forums like StackOverflow.  Good luck!
msg414061 - (view) Author: aprpp (aprpp) * Date: 2022-02-26 03:30
The platform i build python3.7.12 on is Ubuntu18.04, I would like to know how the modules I fail to build, like _ctypes, should be added in Modules/Setup.
The steps for my build are:
1.tar -zxvf Python-3.7.12.tgz && cd Python-3.7.12 
2.edit Modules/Setup, add modules build definitions in the Modules/Setup
3../configure LDFLAGS="-static" --disable-shared --prefix=/home/python3
4.make LDFLAGS="-static" LINKFORSHARED=" "

How to build python3.7 statically without relying on editing Modules/Setup
msg414063 - (view) Author: aprpp (aprpp) * Date: 2022-02-26 03:35
As shown in the attachment, how should I add the definition of module _ctypes to Modules/Setup? Modules like _ctypes are not given in Modules/Setup.dist, I really don't know what they depend on
msg414065 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2022-02-26 04:08
Sorry, I'll repeat: "Successfully building a statically-linked version of Python depends greatly on the environment in which you are trying to build it and is really beyond the scope of this bug tracker." Note, a quick web search found this page which should give you some suggestions on what dev packages need to be installed in an Ubuntu 18.04 environment. But also note that the directions there are for a normal, non-static Python build using setup.py and not Modules/Setup which, again, we don't normally test for 3.7. Good luck!

https://linuxize.com/post/how-to-install-python-3-7-on-ubuntu-18-04/
msg414066 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2022-02-26 04:15
P.S. One other suggestion: try building a non-static version of Python 3.7 first, i.e. without modifying Modules/Setup, and, once you get that working, it should be easier to examine the output from the build and copy those paths that setup.py found into your Modules/Setup.
msg414069 - (view) Author: aprpp (aprpp) * Date: 2022-02-26 04:55
I'm really sorry, I would like to know what environment is the official recommendation for static python3.7 compilation? What are the steps and commands for compilation officially required? Because the static python3.7 is very important to me, it has been a week and it has not been compiled successfully.Hope to get official help.Thanks
msg414073 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2022-02-26 05:30
“I would like to know what environment is the official recommendation for static python3.7 compilation.”

There is no official recommendation. As I’ve mentioned, we normally do not build with modified Modules/Setup configurations when developing and releasing Python. It’s complicated. That’s why setup.py and using Distutils to build the standard library modules was introduced years ago. Most users don’t need a statically linked Python. Please accept that you need to look elsewhere for assistance.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 91010
2022-02-26 05:30:36ned.deilysetstatus: open -> closed

messages: + msg414073
2022-02-26 04:55:50aprppsetstatus: closed -> open

messages: + msg414069
2022-02-26 04:15:04ned.deilysetmessages: + msg414066
2022-02-26 04:08:58ned.deilysetstatus: open -> closed

messages: + msg414065
2022-02-26 03:35:47aprppsetfiles: + Setup.PNG

messages: + msg414063
2022-02-26 03:30:45aprppsetmessages: + msg414061
2022-02-26 03:12:34aprppsetstatus: closed -> open
2022-02-26 02:21:18ned.deilysetstatus: open -> closed
resolution: out of date
messages: + msg414059

stage: resolved
2022-02-26 01:21:59aprppsetmessages: + msg414054
2022-02-25 21:22:41terry.reedysetnosy: + ned.deily
2022-02-25 03:46:49aprppcreate