C GUI, with a C++ backbone?

547 Views Asked by At

I have a simple (and also trivial) banking application that I wrote in C++. I'm on ubuntu so I'm using GNOME (GTK+). I was wondering if I could write all my GUI in C/GTK+ and then somehow link it to my C++ code. Is this even possible?

Note: I don't want to use Qt or GTKmm, so please don't offer those as answers.

5

There are 5 best solutions below

2
On BEST ANSWER

Yes, it's a very easy thing to do. All you have to do is expose some of the C++ functions as "extern C" so that the event handlers and callbacks in your UI code can call them.

In the case that you can't change the existing C++ source - no problem. just write a C++ shim for your UI, extern those functions, and call backend functions from there.

0
On

I don't see why not, with appropriate extern "C" usage so your C code can call into C++. Now, granted, you're probably making it a bit harder on yourself, but it's theoretically sound.

0
On

Like others propose you can write a C wrapper for your C++ library. But you can also write the front-end in C++, even if you only use the C subset. I can understand if you don't like the language mixing, but it is the easiest way, because you save the time to write the wrapper.

0
On

How about using wxWidgets instead?

0
On

You can just compile your GTK/C code as C++ without using GTKmm, and use the C++ code natively.

Most sane C libraries can be used from native C++ code, and GTK+ is fundamentaly a C library.