程序代码如下:
/* -*-coding: utf-8;-*- */
/* gtkhello.c -- traditional GTK+ Hello program */
#include <gtk/gtk.h>
void hello(GtkWidget *widget, gpointer data)
{
g_print("Hello, World!\n");
}
/* standard event handlers */
gint delete_event(GtkWidget *widget, GdkEvent event, gpointer data)
{
/* when this function returns FALSE, the delete-event
signal becomes a destroy signal */
return FALSE;
}
void end_program(GtkWidget *widget, gpointer data)
{
/* End the main loop */
gtk_main_quit();
}
int main(int argc, char **argv)
{
GtkWindow *window;
GtkButton *button;
/* Initialize GTK+ */
gtk_init(&argc, &argv);
/* create window, set default height and width to 200 pixels */
window = g_object_new(GTK_TYPE_WINDOW,
"default-height", 200,
"default-width", 200,
"border-width", 12,
"title", "GtkHello",
NULL);
/* add signal handlers for window */
g_signal_connect(window,
"delete-event", G_CALLBACK(delete_event),
NULL);
g_signal_connect(window,
"destroy", G_CALLBACK(end_program),
NULL);
/* create a button */
button = g_object_new(GTK_TYPE_BUTTON,
"label", "_Hello, World!\nClick Here.",
"use-underline", TRUE,
NULL);
/* install signal handlers for button */
g_signal_connect(button,
"clicked", G_CALLBACK(hello),
NULL);
g_signal_connect_swapped(button,
"clicked", G_CALLBACK(gtk_widget_destroy),
window);
/* pack the button into the window, show all of its contents */
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(button));
gtk_widget_show_all(GTK_WIDGET(window));
/* start main event loop */
gtk_main();
return 0;
}
按照书上的说明用gcc -o gtkhello gtkhello.c `pkg-config --cflags --libs gtk+2.0`编译,出现下面的问题,请问怎么解决,谢谢!
Package gtk+2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+2.0' found
gtkhello.c:4:21: 错误: gtk/gtk.h:No such file or directory
gtkhello.c:6: 错误: expected ‘)’ before ‘*’ token
gtkhello.c:12: 错误: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘delete_event’
gtkhello.c:19: 错误: expected ‘)’ before ‘*’ token
gtkhello.c: 在函数 ‘main’ 中:
gtkhello.c:27: 错误: ‘GtkWindow’ 未声明 (在此函数内第一次使用)
gtkhello.c:27: 错误: (即使在一个函数内多次出现,每个未声明的标识符在其
gtkhello.c:27: 错误: 所在的函数内只报告一次。)
gtkhello.c:27: 错误: ‘window’ 未声明 (在此函数内第一次使用)
gtkhello.c:28: 错误: ‘GtkButton’ 未声明 (在此函数内第一次使用)
gtkhello.c:28: 错误: ‘button’ 未声明 (在此函数内第一次使用)
gtkhello.c:34: 错误: ‘GTK_TYPE_WINDOW’ 未声明 (在此函数内第一次使用)
gtkhello.c:39: 错误: ‘NULL’ 未声明 (在此函数内第一次使用)
gtkhello.c:43: 错误: ‘delete_event’ 未声明 (在此函数内第一次使用)
gtkhello.c:47: 错误: ‘end_program’ 未声明 (在此函数内第一次使用)
gtkhello.c:51: 错误: ‘GTK_TYPE_BUTTON’ 未声明 (在此函数内第一次使用)
gtkhello.c:53: 错误: ‘TRUE’ 未声明 (在此函数内第一次使用)
gtkhello.c:58: 错误: ‘hello’ 未声明 (在此函数内第一次使用)
gtkhello.c:62: 错误: ‘gtk_widget_destroy’ 未声明 (在此函数内第一次使用)
weiyuan@weiyuan-desktop:~/program/gnome-2-examples/chapter3/gtkhello$ gcc -o gtkhello gtkhello.c `pkg-config --cflags --libs gtk+`
gtkhello.c: 在函数 ‘main’ 中:
gtkhello.c:39: 警告: 赋值时将整数赋给指针,未作类型转换
gtkhello.c:54: 警告: 赋值时将整数赋给指针,未作类型转换
/tmp/ccsgU8um.o: In function `main':
gtkhello.c:(.text+0x9d): undefined reference to `g_object_new'
gtkhello.c:(.text+0xac): undefined reference to `G_CALLBACK'
gtkhello.c:(.text+0xcb): undefined reference to `g_signal_connect'
gtkhello.c:(.text+0xd7): undefined reference to `G_CALLBACK'
gtkhello.c:(.text+0xf6): undefined reference to `g_signal_connect'
gtkhello.c:(.text+0x12b): undefined reference to `g_object_new'
gtkhello.c:(.text+0x13a): undefined reference to `G_CALLBACK'
gtkhello.c:(.text+0x159): undefined reference to `g_signal_connect'
gtkhello.c:(.text+0x165): undefined reference to `G_CALLBACK'
gtkhello.c:(.text+0x185): undefined reference to `g_signal_connect_swapped'
collect2: ld 返回 1
gtk程序编译问题?
-
- 帖子: 28
- 注册时间: 2007-05-06 10:56
- yjsword
- 帖子: 524
- 注册时间: 2007-03-14 20:33
- 来自: 南京
- 联系:
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
-
- 帖子: 28
- 注册时间: 2007-05-06 10:56