Skip to content

abi3t migration howto: Windows link fails with LNK2001 "unresolved external symbol PyInit_<name>" — export-symbol step is missing #158098

Description

@sbSteveK

Documentation

Documentation: https://docs.python.org/3.15/howto/abi3t-migration.html

The abi3t migration howto instructs authors to remove PyInit_ and define PyModExport_ instead (PEP 793). For build tools without native abi3t support, the "Setting up the build" note says the extension "will later need to name and tag the resulting extension manually," and "Tagging and distribution" covers those two manual steps: the filename and the wheel tag.

On Windows there is a third manual step that isn't documented: the linker export list. setuptools (no abi3t support yet, see pypa/setuptools#5205) passes /EXPORT:PyInit_ to the MSVC linker. Since the abi3t module no longer defines PyInit_, following the guide leads to a guaranteed link failure:

code

LINK : error LNK2001: unresolved external symbol PyInit__awscrt
_awscrt.cp315t-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
This doesn't reproduce on Linux/macOS (no export lists there), so it only surfaces at the end of an otherwise-successful port. We hit it migrating awscrt (awslabs/aws-crt-python#768) after the Linux and macOS abi3t builds were already green.

Workaround (setuptools):

python

class my_build_ext(setuptools.command.build_ext.build_ext):
    def get_export_symbols(self, ext):
        symbols = super().get_export_symbols(ext)
        if BUILDING_ABI3T:
            symbols = [s.replace('PyInit_', 'PyModExport_') for s in symbols]
        return symbols

Suggested fix: add a sentence to "Tagging and distribution", e.g.:

On Windows, also ensure your build exports PyModExport_ rather than PyInit_; build tools without abi3t support pass /EXPORT:PyInit_ to the linker, which fails because that function no longer exists. With setuptools, override build_ext.get_export_symbols().

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsdocsDocumentation in the Doc dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions