本文介绍了我可以将MinGW编译的Python扩展与Visual C ++编译的扩展一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows下无法编译Python扩展程序时,我问了一个问题.答案之一不能回答我的问题,但值得单独提出一个问题.

Having trouble compiling a Python extension under Windows, I've asked a question.One of the answers does not answer my question but is worth asking as a question on its own.

考虑到Windows下的Visual C ++编译的Python发行版,如果我将Visual C ++编译的扩展名与MinGW编译的扩展名一起使用,会不会有任何问题?

Given a Visual C++ compiled Python distribution under Windows, would I have any problems if I use Visual C++ compiled extensions along with MinGW compiled ones?

当它比配置MS编译器更容易时,这将使我诉诸MinGW.

This would allow me resort to MinGW when it is easier than configuring MS compiler.

推荐答案

它不受官方支持,但我认为它应该可以工作. Python公开了extern "C"函数(具有C链接),因此您应该能够从MSVC调用它们.但这仅仅是Python本身.那扩展呢? PyMODINIT_FUNC中也有extern "C",因此也可以从MSVC调用它.通过函数指针传递给Python的函数也应该起作用,因为它们默认情况下使用cdecl调用约定,但是由于它们是由指针调用的,因此不需要C链接(或C名称修饰).总结起来,应该是Just Work™.

It's not officially supported, but I think it should work. Python exposes extern "C" functions (with C linkage), so you should be able to call them from MSVC. But that's only Python itself. What about extensions? PyMODINIT_FUNC also has extern "C" in it, so that allows to call it from MSVC, too. Functions that you pass to Python by function pointer should also work, because they use cdecl calling convention by default, but do not need C linkage (or C name mangling) because they are called by pointer. To sum up, it should Just Work™.

这篇关于我可以将MinGW编译的Python扩展与Visual C ++编译的扩展一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:44