为什么 Python on Windows 需要使用相同版本的 Microsoft Visual C++ 来构建本机扩展?

Why would Python on Windows require using the same version of Microsoft Visual C++ to build native extensions?

扩展只是动态的 link 库,跨不同版本的 MSVC 应该没有问题。

许多扩展需要访问或创建具有相同字节布局的 CPython 对象,它们必须由主程序分配,它们必须可由垃圾收集器等管理。

Python 可以毫无问题地调用任何 DLL(例如,使用 ctypes),但扩展不仅仅是一个 DLL,而且需要的不仅仅是调用对流兼容性。

Microsoft 编译器的不同版本link 到版本特定的 C 运行时库。 IIRC,IO和内存分配存在差异。如果扩展不依赖于版本之间变化的 C 运行时行为,则扩展模块将起作用。但是可以引用任意 C 代码的扩展模块可能会在不同的运行时库中引起不兼容。 "You must use the same version." 比 "If you only use this subset of C, then you can use any version; otherwise, you must use the same version."

容易多了