0

This page documents the different versions of the Microsoft Visual C++ compiler needed for each Python version: https://wiki.python.org/moin/WindowsCompilers

I would like to use MinGW instead of Microsoft to compile a C library for 64-bit Windows 8.1, but I have read that MinGW-w64/mingwpy does not support Python 3.5: Make cffi use MinGW under Python 3.5 on Windows

I also see http://mxe.cc/ for cross-compiling to Windows, but it too uses the MinGW-w64 toolchain.

If I use CFFI's ABI in-line mode for the Python interface, can I compile a DLL for the C library once (with compatibility to Microsoft Visual C++ 10.0) and use it with both Python 3.4 and 3.5? If so, is compatibility with Python 3.5 achieved because of static linking to the DLL? I don't understand the subtleties of dynamic vs. static linking.

Community
  • 1
  • 1
hiccup
  • 277
  • 2
  • 8
  • AFAIK in CFFI's ABI mode you're not building an extension module that links with the Python DLL. It's using `LoadLibrary` and `GetProcAddress` to dynamically load and call functions in your DLL -- much like ctypes, but with a cleaner API that can do a lot of the tedious work for you by automatically parsing C header files. – Eryk Sun Nov 21 '16 at 23:47
  • If you're building with MinGW, the DLL itself will be linked to msvcrt.dll instead of the C runtime that Python uses, so the library API should avoid file descriptor and `FILE` pointer arguments (each CRT has its own low and standard I/O implementation that wraps Windows `File` handles) and encapsulate its memory management (each CRT may have its own heap, though I think the Universal CRT uses the default process heap) or require the client to allocate all memory. Other thread-local state such as `errno` and the locale is also unique to each CRT. – Eryk Sun Nov 21 '16 at 23:52

1 Answers1

0

If you use CFFI's ABI in-line mode, you don't need to compile anything. You just need to install CFFI, which comes precompiled for Windows.

If you use the recommmended CFFI's API mode, you need a compiler. The complete requirements on Windows are too complicated for me to make sense, but note that the CFFI-generated extension module should be compiled in what CPython calls the "stable ABI" mode. That is, a single compiled .pyd is enough for all versions of CPython 3.x. I would guess that you can pick whichever version of CPython you have the proper compiler toolchain for, and use it to compile the .pyd.

Armin Rigo
  • 12,048
  • 37
  • 48
  • When you say I don't need to compile anything with the ABI in-line mode, does that mean CFFI will read my source code? Does Python's interpreter replace a compiler? – hiccup Dec 01 '16 at 13:31
  • In ABI mode, you only put C function declarations inside ``ffi.cdef()``, and that is parsed by CFFI without using a compiler. There is no actual C source code in that mode. – Armin Rigo Dec 04 '16 at 09:43