1

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?

AbhinavChoudhury
  • 1,167
  • 1
  • 18
  • 38
  • 2
    Haven't used it myself, but [Boost.Python](http://www.boost.org/doc/libs/1_57_0/libs/python/doc/index.html) might be able to help. – chris Feb 17 '15 at 17:31
  • Launching a C++ executable is a fairly heavyweight operation, so I'd only do that if you didn't have to do it very often. (e.g. no more often than once a second). Another possibility would be to launch the C++ executable once and have it keep running, and then have your GUI code communicate with it via stdin/stdout, TCP socket, or some other IPC mechanism. – Jeremy Friesner Feb 17 '15 at 17:33
  • 2
    possible duplicate of [Calling C/C++ from python?](http://stackoverflow.com/questions/145270/calling-c-c-from-python) – rrirower Feb 17 '15 at 17:34

1 Answers1

2

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.

Bort
  • 2,423
  • 14
  • 22