Invoking C++ from C
I'm not sure if this is a simple thing or not, but so far I can't get it to work.
I am building a gtk/glade based GUI using a mixture of C and C++. Essentially, I have to do my event handlers in C because that is what gtk expects, but I want to do the bulk of my work in C++. So, I have a C++ framework that defines classes to open forms and define widgets and invoke gtk through the gtkmm libraries, and all that works. When you click on a button on the resulting GUI, the handler for that function is a C routine, compiled separately, and referenced in the C++ code as an extern "C" module. So, I want to go from that handler in C right back to C++ and I do not seem to be able to do it. Here is a sample. In the file "sighandlers.c" I have this, which is a function invoked by clicking on a button on my GUI. Code:
Code:
void connect_with_client() Here is the code: Code:
char *geturi() Problem is that it won't link. I keep getting this message: Code:
cmd_button_handlers.o: In function `connect_with_client': Code:
extern char *geturi(); When I google for this, what I come up with is lots of people trying to mix C# and C++. I haven't found anything useful. Going from C++ to C is very straightforward. But how do I go back? |
Hi -
Yes, in general you can certainly co-mingle C and C++ (call C from C++ and, with relatively few restrictions, also call C++ from C). You're declaring your C++ entries as C-callable with "extern C{}", aren't you? 'Hope that helps .. pSM |
Quote:
Usually, I don't do this code mixing this way; since gtk is single threaded I generally spawn multiple threads and the gtk thread signals other threads to do things. The gtk thread will be C, and the other threads are whatever I deem necessary. This particular interface is so simple that I decided to do it all in one thread, but some of it has to be C. Properly placing some extern "C" for C++ code to be called from C does in fact work. Thanks. |
Quote:
|
All times are GMT -5. The time now is 07:42 PM. |