1

I have a C/C++ project in which I am using swig to interface with python. I would like to know if I have to build against every version of python lib to have my script be supported or is there a simpler way. I understand that I can use distutils to build on the user machine but this is not always true. I would like to know how other projects handle this.

ZNackasha
  • 755
  • 2
  • 9
  • 29
  • Yes. I recommend though that you create your library with a proper ABI and only build the Python wrapper using the different versions of Python. A version for 2.7 and 3.x should be sufficient. – Jens Munk Apr 19 '19 at 18:20
  • So I don't have to build one for 3.4 - 3.6 and so on – ZNackasha Apr 19 '19 at 19:05
  • Also is this true for both windows and linux – ZNackasha Apr 19 '19 at 19:16
  • Python 3.4, 3.5, etc. are not 100% binary compatible - some struct definitions are changed, but I have managed to use SWIG libraries for both Python 3.4 and 3.5. – Jens Munk Apr 19 '19 at 20:01
  • 1
    You can read about here about how to constrain the usage of Python 3.x to ensure a stable ABI, https://docs.python.org/3/c-api/stable.html – Jens Munk Apr 19 '19 at 20:05

1 Answers1

1

Short answer - yes, you do have to build different SWIG wrappers for each Python version you want to support (3.6, 3.7, 3.8 etc).

Even though there is Python Stable ABI, as for today (March 2020) this is not possible to use because it's not implemented in SWIG (see #1613) yet.

There is a PR in SWIG #1009 open, however it's open for almost three years though.

The Godfather
  • 4,235
  • 4
  • 39
  • 61