12

I've read several threads about some of the differences between Cython and Swig and have implemented both techniques, but I am still not sure what route is the best route to take. Basically I have been working on a C++ library and I would like to expose those functions to Python. Cython seemed rather complicated and required me to write several .pyx files for every C++ class that I needed to expose whereas SWIG just did the work for me. I don't have a lot of experience with either one of these wrapping methods to date, but it seems that SWIG is a clear winner for wrapping my C++ code. So what is the controversy? Why would I spend hours writting .pyx files in Cython to wrap my C++ when I could just write one simple .i file in SWIG? Furthermore, I use CMake as my build tool and it was WAY easier to build SWIG with CMAKE than with Cython. I feel that I must be missing something because even big projects like OpenCV are not using SWIG and before I dedicate my project to SWIG, I want to find out why I would rather use Cython or nothing at all. Here is a summary:

My project: C++ source code is primary

  • Python is a nice to have, just want a path of least resistance to expose the majority of my C++ code.
  • Writting wrapper code sucks because now I have two places to maintain an API--I just want one, the C++ code.

Any advice is greatly appreciated. Also, I was curious about xdress.org--seems like that project has died though.

user985030
  • 1,557
  • 1
  • 16
  • 32
  • 1
    See https://scipy-lectures.github.io/advanced/interfacing_with_c/interfacing_with_c.html – rth Jun 02 '15 at 10:15
  • thanks @rth! That was a great read. – user985030 Jun 02 '15 at 14:11
  • btw, regarding your other question, xdress looks rather active to me (see [last commits on github](https://github.com/xdress/xdress/network)). – rth Jun 02 '15 at 14:19

0 Answers0