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.