Menu

#154 SWIG C++ Python 64-bit extensions for working MinGW64 GCC 9.2

v1.0 (example)
open
nobody
None
5
2021-04-24
2020-02-22
Andrew G.
No

By applying the -static and -lucrtbase linker options, I've got several C/C++/Fortran extensions working with MinG64 and Python 3.8 (64-bit) on Windows. Whoever added the ucrtbase library did some excellent work.

SWIG-generated C++ wrappers do not work (they crash on loading). I used the compilation option -DMS_WIN64, but this did not fix the problem. I've attached the source files. The command lines for compilation and linking that I used are given in file pysimcpp.h. Compilation and linking can be peformed from either cmd.exe or MSYS2 terminals (both fail to produce working extensions).

Is there another option I need to use? Any ideas would be much appreciated.
Andrew.

5 Attachments

Discussion

  • Andrew G.

    Andrew G. - 2020-03-10

    I've also tried building the extension for 32-bit Python 3.8 (CPython) on Windows (also linking against ucrtbase). I still a crash when the extension is imported. The examples attached work correctly on a 64-bit Ubuntu system with Python 3.6.
    Andrew.

     
  • Andrew G.

    Andrew G. - 2020-04-08

    Did a bit more probing and identified exception: Heap Corruption Exception 0xC0000374

    C:\PySimcpp>c:\python38_x64\python -q -X faulthandler

    import _pysimcpp
    Windows fatal exception: code 0xc0000374

    Current thread 0x00000bd4 (most recent call first):
    File "<frozen importlib._bootstrap="">", line 219 in _call_with_frames_removed
    File "<frozen importlib._bootstrap_external="">", line 1101 in create_module
    File "<frozen importlib._bootstrap="">", line 556 in module_from_spec
    File "<frozen importlib._bootstrap="">", line 657 in _load_unlocked
    File "<frozen importlib._bootstrap="">", line 975 in _find_and_load_unlocked
    File "<frozen importlib._bootstrap="">", line 991 in _find_and_load
    File "<stdin>", line 1 in <module></module></stdin></frozen></frozen></frozen></frozen></frozen></frozen>

    My MSYS2 MinGW64 installation updated to GGC 9.3 - problem still occurs.

     

    Last edit: Andrew G. 2020-04-08
  • Andrew G.

    Andrew G. - 2021-04-24

    Good news: There's now a UCRT toolchain for MSYS2, which fixes the problem.

    pacman -S mingw-w64-ucrt-x86_64-toolchain

    This toolchain installs to MSYS2\ucrt64). To produce a working extension for a 64-bit Python (e.g. 3.8), put this directory on Windows PATH, then compile and link the SWIG wrapper. The necessary commands are given as comments in pysimcpp.h.

    From what I've read, the libstdc++ in MSYS2\Mingw64 is built against msvcrt - which is why C++ extensions linked to ucrt with the normal MinGW64 toolchain crash.

     

    Last edit: Andrew G. 2021-04-25

Log in to post a comment.

MongoDB Logo MongoDB