#include <gnome.h>
#define VERSION "1.0"
/* "callback" function (signal handler) which will quit the application*/
static void exit_hello(GtkWidget *widget, gpointer data)
{
gtk_main_quit ();
}
/* callback function for when the window closes */
static int delete_event(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
return FALSE; /* false means continue with closing the window */
}
int main(int argc, char *argv[])
{
GtkWidget *app; /* pointer to our main window */
GtkWidget *w;
/* initialize gnome */
gnome_init("hello_world", VERSION, argc, argv);
/*create main window*/
app = gnome_app_new("hello_world", "Hello World (Gnome Edition)");
/* connect "delete_event" (happens when the window is closed */
gtk_signal_connect(GTK_OBJECT(app), "delete_event",
GTK_SIGNAL_FUNC(delete_event), NULL);
/* show all the widgets on the main window and the window itself */
gtk_widget_show_all(app);
/* run the main loop */
gtk_main();
return 0;
}
编译的时候按照网上提供的Makefile
CFLAGS=-g -Wall `gnome-config --cflags gnome gnomeui` LDFLAGS=`gnome-config --libs gnome gnomeui` all: hello_world clean: rm -f hello_world core
编译失败 原因是在ubuntu 下面 gnome-config 被 pkg-config取代了 gnome gnomeui 被 libgnome-2.0 libgnomeui-2.0 取代 所以Makefile改成: all: hello GCC=gcc FILE=hello CFLAGS+=$(shell pkg-config --cflags libgnomeui-2.0 gtk+-2.0) LIBS+=$(shell pkg-config --libs libgnomeui-2.0 gtk+-2.0) .c.o: $(GCC) -c $< $(CFLAGS) $(FILE).o: $(FILE).c hello: $(FILE).o $(GCC) -o hello $(FILE).o $(CFLAGS) $(LIBS) clean: -rm hello *.o
转载于:https://blog.51cto.com/inkfish/578361