我对编程很陌生,特别是在涉及如何包含库和类似的活动时.我过去一直在使用
Python进行编程,我一直在使用GTK来创建窗口,这也是我用c编程时打算做的事情.为了开始,这是我的代码:
原文链接:https://www.f2er.com/ubuntu/347425.html#include <stdlib.h> #include <gtk/gtk.h> static void helloWorld (GtkWidget *wid,GtkWidget *win) { GtkWidget *dialog = NULL; dialog = gtk_message_dialog_new (GTK_WINDOW (win),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO,GTK_BUTTONS_CLOSE,"Hello World!"); gtk_window_set_position (GTK_WINDOW (dialog),GTK_WIN_POS_CENTER); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } int main (int argc,char *argv[]) { GtkWidget *button = NULL; GtkWidget *win = NULL; GtkWidget *vBox = NULL; /* Initialize GTK+ */ g_log_set_handler ("Gtk",G_LOG_LEVEL_WARNING,(GLogFunc) gtk_false,NULL); gtk_init (&argc,&argv); g_log_set_handler ("Gtk",g_log_default_handler,NULL); /* Create the main window */ win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW (win),400,300); gtk_container_set_border_width (GTK_CONTAINER (win),8); gtk_window_set_title (GTK_WINDOW (win),"test"); gtk_window_set_position (GTK_WINDOW (win),GTK_WIN_POS_CENTER); gtk_widget_realize (win); g_signal_connect (win,"destroy",gtk_main_quit,NULL); /* Create a vertical Box with buttons */ vBox = gtk_vBox_new (TRUE,6); gtk_container_add (GTK_CONTAINER (win),vBox); button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO); g_signal_connect (G_OBJECT (button),"clicked",G_CALLBACK (helloWorld),(gpointer) win); gtk_Box_pack_start (GTK_Box (vBox),button,TRUE,0); button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); g_signal_connect (button,NULL); gtk_Box_pack_start (GTK_Box (vBox),0); /* Enter the main loop */ gtk_widget_show_all (win); gtk_main (); return 0; }
代码取自我在互联网上发现的“Hello world”示例.
我知道这个问题已经得到了答案,但我的情况要复杂得多(至少从我的角度来看).首先,我已经安装了所有必需的包.顺便说一句,我运行Ubuntu 14.04.
main.cpp:2:21: fatal error: gtk/gtk.h: No such file or directory #include <gtk/gtk.h> ^ compilation terminated.
对此特定错误有一个修复,即扩展编译命令,如下所示:g main.cpp -I /usr/include / gtk-2.0.然而,这将提供另一个类似的错误:
In file included from /usr/include/gtk-2.0/gdk/gdk.h:32:0,from /usr/include/gtk-2.0/gtk/gtk.h:32,from main.cpp:2: /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30:21: fatal error: gio/gio.h: No such file or directory #include <gio/gio.h> ^ compilation terminated.
您也可以通过扩展这样的命令来解决这个问题(所有命令都是互联网上的资金,我对此并不十分了解):g -g -Wall -c -o program.o main.cpp -I / usr /include/gtk-2.0 $(pkg-config –libs –cflags glib-2.0).现在cairo.h会出错.
如您所见,存在类似的错误.我不知道出了什么问题,但我必须相信有一个相对容易的解决办法.
此外,我尝试了全新安装的Ubuntu(只需要安装的软件包),并发生相同的错误.