当尝试使用Code :: Blocks编译时,出现了GTK +的例子:
#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_LEVEL_WARNING, g_log_default_handler, NULL); /* Create the main window */ win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (win), 8); gtk_window_set_title (GTK_WINDOW (win), "Hello World"); 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, TRUE, 0); button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); g_signal_connect (button, "clicked", gtk_main_quit, NULL); gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0); /* Enter the main loop */ gtk_widget_show_all (win); gtk_main (); return 0; }
我收到以下错误:
ld.exe||cannot find -lgobject-2.0| ld.exe||cannot find -lglib-2.0| ||=== Build finished: 2 errors, 0 warnings ===|
我已将两者都链接到该项目,但我找不到让它工作的方法。我已经尝试了来自http://www.gtk.org/download-windows.html的捆绑和分离的包。我很确定它必须是简单/愚蠢的东西,但我找不到任何可以帮助我解决这个问题的东西。
答案 0 :(得分:2)
您是否已将包含libglib-2.0.a,libgobject-2.0.a文件的GTK目录添加到链接器搜索目录。
这可以通过以下路径完成:
的 Settings | Compiler and debugger... | Search directories | Linker | Add
即可。
可以在Build Log
窗口中查看编译器/链接器的完整命令行。要启用此功能,请转到:
的 Settings | Compiler and debugger... | Other Settings | Compiler logging | Full command line
强>
我没有遇到丢失的入口点问题,所以也许你的GTK副本已损坏。从GTK+ 2.22
下载一体化软件包确保在Search directories | Compiler
作为附注,您可能需要使用-mms-bitfields
编译项目,可以将其添加到:
Settings | Compiler and debugger... | Other options
只需按原样粘贴标记。
答案 1 :(得分:0)
当code :: blocks运行ld.exe而不是调用它时,例如:-l glib-2.0
它正在调用它-lglib-2.0
在code :: block的链接器选项中的lib名称之前添加一个空格应该修复它。