`Py_BUILD_CORE` causes different link-time behavior on Windows and Linux

On Windows:

    library.cpp.obj : error LNK2019: unresolved external symbol _Py_NoneStruct referenced in function "struct _object * __cdecl PyInit_skbuild_test(void)" (?PyInit_skbuild_test@@YAPEAU_object@@XZ)
    skbuild_test.cp311-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals

Is this excepted on Windows?

reproducer: GitHub - oraluben/skbuild-test
error log: cleanup · oraluben/skbuild-test@d22a862 · GitHub

My guess is that it is coming from skbuild not python.
Ask would ask them why this happens.


Thanks for your reply! I first created an issue in skbuild but later I found it more possibly related to CPython itself.
I’ve found a workaround, which is not to define Py_BUILD_CORE globally, instead just define it before including internal headers, and the error gone:

But it’s still not clear how this change affects the linker to me.

skbuild issue: `error LNK2019: unresolved external symbol` during Windows build · Issue #803 · scikit-build/scikit-build · GitHub

Becuase the Windows build has a bug in it?

Why don’t you want to ask the people that wrote skbuild for help?