Live data from Hacker News

Swig – Connect C/C++ programs with high-level programming languages

swig.org

1–10 of 90 posts

Re: Swig – Connect C/C++ programs with high-level programming languages

#3
In my personal experience, to use a very small C library in python in a work project, my life became simpler when I ditched swig and just called the C API from python.

Then I had a pure python codebase that I could run on any python version without recompilation, and I no longer had the complication of having to deal with swig's different versions across different distribution releases.

For much bigger projects I could imagine that the situation can be different.

Re: Swig – Connect C/C++ programs with high-level programming languages

#4
I got a great speedup using C++ with pybind11 for my Python backend, 30x if I remember correctly. It was for an app that detects wether words rhyme. I was about to release it but ditched it as soon as ChatGPT came out (it can find rhymes easily, and sometimes better).

Re: Swig – Connect C/C++ programs with high-level programming languages

#6
I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters.

CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).

Re: Swig – Connect C/C++ programs with high-level programming languages

#7

I got a great speedup using C++ with pybind11 for my Python backend, 30x if I remember correctly. It was for an app that detects wether words rhyme. I was about to release it but ditched it as soon as ChatGPT came out (it can find rhymes easily, and sometimes better).

There's nanobind by the same author as pybind11 that's even faster: https://github.com/wjakob/nanobind

Re: Swig – Connect C/C++ programs with high-level programming languages

#8
post #3

In my personal experience, to use a very small C library in python in a work project, my life became simpler when I ditched swig and just called the C API from python. Then I had a pure python codebase that I could run on any python version without recompilation, and I no longer had the complication of having to deal with swig's different versions across different distribution releases. For much bigger projects I cou…

How do you call C API from python? Through executable + stdin/stdout?

Re: Swig – Connect C/C++ programs with high-level programming languages

#9
I know there are many newer tools with various advantages. But I've used SWIG bindings in production for almost 20 years and some of the code is still live. An amazing achievement of the SWIG developers. So the stability and longevity are big advantages as well as the ability to adjust how the C++ code is exposed without actually changing the C++ sources.

Re: Swig – Connect C/C++ programs with high-level programming languages

#10
post #8
post #3

In my personal experience, to use a very small C library in python in a work project, my life became simpler when I ditched swig and just called the C API from python. Then I had a pure python codebase that I could run on any python version without recompilation, and I no longer had the complication of having to deal with swig's different versions across different distribution releases. For much bigger projects I cou…

How do you call C API from python? Through executable + stdin/stdout?

https://docs.python.org/3/library/ctypes.html
Post reply on HN