You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyMODINIT_FUNC does not apply __declspec(dllexport) on Windows #141671
adds any special linkage declarations required by the platform, and
for C++, declares the function as extern "C".
Specifically, the special linkage declarations should be __attribute__ ((visibility ("default"))) on GCC/clang, and __declspec(dllexport) on Windows.
However, the definition assumes we're building CPython itself, and only adds a linkage declaration with Py_ENABLE_SHARED -- that is, when Python itself is built with a shared library.
A comment directive in the source code, of the form #pragma comment(linker, "/export: definition ").
Setuptools, and historically distutils, does (2) -- and so does, presumably, any other build system for native extensions on Windows.
However, this breaks for modules that define the PEP-793PyModExport hook.
It would be great to switch to the preferred (1), and then tell Setuptools to avoid /EXPORT for 3.15+.
I'd rather let this change have the full alpha/beta period before it hits production. It's old, platform-specific, widely used, and tied to build systems.
Activity
pythongh-141671: Use __declspec(dllexport) when not building core
encukou commentedon Nov 18, 2025
I filed a setuptools issue: pypa/setuptools#5118
AraHaan commentedon Dec 29, 2025
I personally think this would be safe to be backported to 3.12, 3.13, 3.14 as adding
__declspec(dllexport)toPyMODINIT_FUNCdoes not break anything.Also then the setuptools patch would also apply to those versions of python as well when they upgrade the package.
This is because currently what I do to work around this was to
in my C extension code which I feel could have been avoided entirely.
gh-141671: PyMODINIT_FUNC: apply `__declspec(dllexport)` on Windows (G…
encukou commentedon Jan 7, 2026
I'd rather let this change have the full alpha/beta period before it hits production. It's old, platform-specific, widely used, and tied to build systems.
rgommers commentedon Jan 13, 2026
For clarity: I think you meant that
setuptools/distutilsdoes (3), not (2). And other build systems/backends do (2).pythongh-141671: PyMODINIT_FUNC: apply `__declspec(dllexport)` on Win…