AbhinavChoudhury
AbhinavChoudhury

Reputation: 1187

What is the best way to interface C++ code with Python?

I am trying to create an application in which the GUI is programmed in Python (Tkinter) and I have a library in C++ that I want to interface with this GUI code. (Please, no comments on why the GUI and the application library are in separate languages).

One approach that immediately comes to mind is to compile the C++ library into an executable and write python wrappers that call this executable ( via system() ) with specific arguments and consume the output.

I am not sure what the performance implications are for such an implementation. Also I do not want to change the library into Python. Any better suggestions or comments on the approach?

Upvotes: 1

Views: 1778

Answers (1)

Bort
Bort

Reputation: 2491

There are several ways for doing this. One obvious way was already stated by chis. Another good way of interfacing C++ with Python is by using swig. It all comes down how complex your structures / classes are.

So the C++ code is going to be a module in python and can be called by the interface as any other python function.

Upvotes: 2

Related Questions