C GUI, with C ++ base?

I have a simple (as well as trivial) banking application that I wrote in C ++. I am on ubuntu, so I am using GNOME (GTK +). I was wondering if I could write my entire GUI in C / GTK + and then somehow link it to my C ++ code. Is it possible?

Note: I do not want to use Qt or GTKmm, so please do not suggest them as answers.

+1


a source to share


5 answers


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



In case you cannot modify the existing C ++ source, no problem. just write a C ++ shim for your UI, inject these functions and call the backend functions from there.

+5


a source


I don't understand why not, with an appropriate extern "C" so your C code can call in C ++. Now, given, you're probably overcomplicating yourself a little, but that sounds in theory.



+1


a source


Like others have suggested, 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 a subset of C. I can understand if you don't like mixing languages, but this is the easiest way because you save time to write the wrapper.

0


a source


How about using wxWidgets instead?

0


a source


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

Most normal C libraries can be used from native C ++ code, and GTK + is the fundamental C library.

0


a source







All Articles