Hacker News new | past | comments | ask | show | jobs | submit login

FFI into C++ is a lot of work in any language. A lot of projects just define a plain C wrapper for the C++ code they want to call, and call that C code from whatever their glue language is.

However, Python does have CLIF[1], which is the nicest solution for calling into C++ that I'm aware of.

[1] https://github.com/google/clif





Not in enough detail to have an informed opinion.


There's also Boost.Python, which boasts "seamless interoperability between C++ and Python": https://www.boost.org/doc/libs/1_70_0/libs/python/doc/html/i...

(In general, the Boost C++ libraries are well-renowned in the C++ world.)


I think the biggest thing, for me is Cython. I've not seen anything quite like it in other languages. It allows you to compile python code to c, with gradual typing. It also allows you to write c code inline w/ your python or interface with other C/C++ libraries. https://cython.org/ Other languages will be pressed to beat its utility (esp in the scientific computing world)


pybind11 is a modern version of the Boost Python approach to Python bindings. Header only and can be installed trivially from PyPi. I like it well enough that I even use it for binding C code. Especially because it has nice numpy array support (albeit a little underdocumented).


In my experience it’s far from what I’d call seamless but it’s definitely good enough


On Windows it is much better, thanks to COM and now UWP, which improves COM a lot regarding what is exposed across the ABI.

Yes, bare bones COM is full of boilerplate, however there are more productive ways to use it.


How does CLIF compare to PyBind11[1]?

[1] https://github.com/pybind/pybind11


Nicest for Python, I assume.

Many languages have FFI. Lua, PHP, etc. https://en.wikipedia.org/wiki/Foreign_function_interface

I don't understand the choice of Python for things like gluing together C programs. Seems like a performant mistake, at the very least.


It’s the 80:20 rule, which naturally doesn’t always holds. Often, however, a small part of the code is responsible for almost all of the performance issues.

By picking the performance sensitive areas of the program to code in C one can often code the rest of the program in a slower more convenient language.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: