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:
G_MODULE_EXPORT void on_button1_clicked(GtkObject *object, gpointer user_data)
{
connect_with_client();
}
the module connect_with_client() is also a C function, in a file named cmd_button_handlers.c, and it currently looks like this (note: not done and primitive)
Code:
void connect_with_client()
{
printf("connect with client button pushed\n");
if(sockfd < 0)
{
char *thisuri = geturi();
char *thisport = getport();
printf("uri %s port %s\n",thisuri,thisport);
sockfd = Tcp_connect("192.168.0.10","2020");
if(sockfd > 0)
{
send(sockfd,"hello from dadsbox",18,0);
printf("sockfd is %d\n",sockfd);
}
}
}
Now, the functions geturi() and getport() are trial functions of mine that are defined in the main C++ file. I say "trial" because what they are supposed to do is fairly obvious from the names, but they are not working.
Here is the code:
Code:
char *geturi()
{
return (char *)(ca.get_uri().c_str());
}
char *getport()
{
return (char *)(ca.get_port().c_str());
}
As you can see, the architecture here is C++ and the intent is to obtain the desired information from a class that has that information tucked away.
Problem is that it won't link. I keep getting this message:
Code:
cmd_button_handlers.o: In function `connect_with_client':
/mnt/sde1/home/jiml/commander/cmd_button_handlers.c:17: undefined reference to `geturi'
/mnt/sde1/home/jiml/commander/cmd_button_handlers.c:18: undefined reference to `getport'
Near the top of the cmd_button_handlers.c file, I do have this prototype:
Code:
extern char *geturi();
extern char *getport();
So, this points to a general problem; moving from C back to C++ when programming a mixed environment.
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?