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: Limitations of building a static python library on Windows (MSVC)
Type: Stage:
Components: Windows Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: maarten, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-11-11 11:09 by maarten, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg380747 - (view) Author: Maarten (maarten) * Date: 2020-11-11 11:09
`PCbuild/readme.txt` contains a little paragraph about how to build a static python library.
The resulting static `python.lib` library contains all python C API functions.

Windows DLL's don't allow missing symbols, so C extensions modules must link with a library containing the python C API symbols.
When a C extension links to the static python library, it will contain a copy of all python symbols.
This means that python C symbols are used twice: once by a static python.exe executable, and once for each C extension (_extension.pyw).

Is there a way to use C extensions with a static Windows python.exe wuch that the python symbols are used only once?
Does a statically built Windows python.exe support C extension modules at all?

Thanks

I'm currently working on a conan build recipe for cpython at https://github.com/conan-io/conan-center-index/pull/1510
Fow now, I'm disabling extensions on a static MSVC build.
msg380835 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-11-12 17:07
> Does a statically built Windows python.exe support C extension modules at all?

I've given this some thought in the past, and I suspect the answer is "no" unless you were to also statically link the extension modules into the same executable (which will likely require code modifications).

That may answer the rest of your queries, but perhaps not. I'll have to give those some more thought.

> For now, I'm disabling extensions on a static MSVC build.

This seems like the best option.
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86487
2020-11-12 17:07:32steve.dowersetmessages: + msg380835
2020-11-11 11:09:04maartencreate