Hello everyone, I am new to c programming and I have a question about gtk2 programming on linux using c. I copied the gtk2 helloworld tutorial from their website and compiled it nicely. Here is the code:
Code:
#include <gtk/gtk.h>
static void hello( GtkWidget *widget, gpointer data )
{
g_print ("Hello World\n");
}
static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
{
g_print ("delete event occurred\n");
return TRUE;
}
static void destroy( GtkWidget *widget, gpointer data )
{
gtk_main_quit ();
}
int main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL);
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
button = gtk_button_new_with_label ("Hello World");
//###############################################################################
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (hello), NULL);
//###############################################################################
g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (window));
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}
I just produces a little dialog box with a button and prints hello world to a terminal when the button is clicked. I would like to split the callback function to a new file to get the hang of multiple c files. But when I try to move the "static void hello" function (at the top of the page) to a new file, I get errors. I am using gcc to compile the two files and make one executable.
How do I compile cleanly?