如何在代码块中设置 GTk 2
how to set up GTk 2 in codeblock
我想设置 gtk2,我做到了:
compiler option:pkg-config --cflags gtk+-2.0
likker option:pkg-config --libs gtk+-2.0
我将路径 gtk2 添加到变量路径并将 gdk-pixbuff 添加到用户变量
但是当我编译下面的代码时;
#include <gtk/gtk.h>
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *menubar;
GtkWidget *filemenu;
GtkWidget *file;
GtkWidget *quit;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 250, 200);
gtk_window_set_title(GTK_WINDOW(window), "menu");
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
menubar = gtk_menu_bar_new();
filemenu = gtk_menu_new();
file = gtk_menu_item_new_with_label("File");
quit = gtk_menu_item_new_with_label("Quit");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(quit), "activate",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
错误未定义引用
错误日志:
||=== gfffnewaa, Debug ===| obj\Debug\main.o||In function main':|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|15|undefined reference togtk_init_abi_check'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|17|undefined
reference to gtk_window_new'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined reference togtk_window_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined
reference to g_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined reference togtk_window_set_position'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined
reference to gtk_window_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined reference tog_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined
reference to gtk_window_set_default_size'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined reference togtk_window_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined
reference to g_type_check_instance_cast'
我很苦恼很迷茫?我该如何解决这个问题?
errors is not defined refrence
||=== gfffnewaa, Debug ===| obj\Debug\main.o||In function main':|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|15|undefined
reference togtk_init_abi_check'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|17|undefined
reference to gtk_window_new'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined
reference togtk_window_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined
reference to g_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined
reference togtk_window_set_position'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined
reference to gtk_window_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined
reference tog_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined
reference to gtk_window_set_default_size'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined
reference togtk_window_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined
reference to g_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined
reference togtk_window_set_title'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|22|undefined
reference to gtk_vbox_new'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|23|undefined
reference togtk_container_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|23|undefined
reference to g_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|23|undefined
reference togtk_container_add'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|25|undefined
reference to gtk_menu_bar_new'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|26|undefined
reference togtk_menu_new'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|28|undefined
reference to gtk_menu_item_new_with_label'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|29|undefined
reference togtk_menu_item_new_with_label'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|31|undefined
reference to gtk_menu_item_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|31|undefined
reference tog_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|31|undefined
reference to gtk_menu_item_set_submenu'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|32|undefined
reference togtk_menu_shell_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|32|undefined
reference to g_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|32|undefined
reference togtk_menu_shell_append'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|33|undefined
reference to gtk_menu_shell_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|33|undefined
reference tog_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|33|undefined
reference to gtk_menu_shell_append'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|34|undefined
reference togtk_box_get_type'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|34|undefined
reference to g_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|34|undefined
reference togtk_box_pack_start'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|36|undefined
reference to g_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|36|undefined
reference togtk_main_quit'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|36|undefined
reference to g_signal_connect_data'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|39|undefined
reference tog_type_check_instance_cast'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|39|undefined
reference to gtk_main_quit'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|39|undefined
reference tog_signal_connect_data'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|42|undefined
reference to gtk_widget_show_all'|
F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|44|undefined
reference togtk_main'| ||=== Build finished: 39 errors, 0 warnings (0
minutes, 1 seconds) ===|
要编译 GTK+ 应用程序,您需要告诉编译器在哪里可以找到 GTK+ 头文件和库。这是通过 pkg-config 实用程序完成的。
对于头文件,您需要在代码块选项中添加以下构建选项。
pkg-config --cflags gtk+-3.0
对于库,您需要在代码块选项中添加以下构建选项。
pkg-config --libs gtk+-3.0
请看一下对你有帮助。
我的问题是我使用了 gtk x64,但是代码块与 gtk x86
一起工作
现在我使用 gtkx86 和 codeblock x86,效果很好。
有时现在有错误,只有我们感到困惑...
我想设置 gtk2,我做到了:
compiler option:pkg-config --cflags gtk+-2.0
likker option:pkg-config --libs gtk+-2.0
我将路径 gtk2 添加到变量路径并将 gdk-pixbuff 添加到用户变量 但是当我编译下面的代码时;
#include <gtk/gtk.h>
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *menubar;
GtkWidget *filemenu;
GtkWidget *file;
GtkWidget *quit;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 250, 200);
gtk_window_set_title(GTK_WINDOW(window), "menu");
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
menubar = gtk_menu_bar_new();
filemenu = gtk_menu_new();
file = gtk_menu_item_new_with_label("File");
quit = gtk_menu_item_new_with_label("Quit");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(quit), "activate",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
错误未定义引用
错误日志:
||=== gfffnewaa, Debug ===| obj\Debug\main.o||In function main':| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|15|undefined reference togtk_init_abi_check'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|17|undefined reference to gtk_window_new'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined reference togtk_window_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined reference to g_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined reference togtk_window_set_position'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined reference to gtk_window_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined reference tog_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined reference to gtk_window_set_default_size'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined reference togtk_window_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined reference to g_type_check_instance_cast'
我很苦恼很迷茫?我该如何解决这个问题?
errors is not defined refrence
||=== gfffnewaa, Debug ===| obj\Debug\main.o||In function main':| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|15|undefined reference togtk_init_abi_check'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|17|undefined reference to gtk_window_new'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined reference togtk_window_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined reference to g_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|18|undefined reference togtk_window_set_position'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined reference to gtk_window_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined reference tog_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|19|undefined reference to gtk_window_set_default_size'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined reference togtk_window_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined reference to g_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|20|undefined reference togtk_window_set_title'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|22|undefined reference to gtk_vbox_new'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|23|undefined reference togtk_container_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|23|undefined reference to g_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|23|undefined reference togtk_container_add'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|25|undefined reference to gtk_menu_bar_new'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|26|undefined reference togtk_menu_new'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|28|undefined reference to gtk_menu_item_new_with_label'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|29|undefined reference togtk_menu_item_new_with_label'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|31|undefined reference to gtk_menu_item_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|31|undefined reference tog_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|31|undefined reference to gtk_menu_item_set_submenu'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|32|undefined reference togtk_menu_shell_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|32|undefined reference to g_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|32|undefined reference togtk_menu_shell_append'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|33|undefined reference to gtk_menu_shell_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|33|undefined reference tog_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|33|undefined reference to gtk_menu_shell_append'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|34|undefined reference togtk_box_get_type'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|34|undefined reference to g_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|34|undefined reference togtk_box_pack_start'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|36|undefined reference to g_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|36|undefined reference togtk_main_quit'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|36|undefined reference to g_signal_connect_data'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|39|undefined reference tog_type_check_instance_cast'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|39|undefined reference to gtk_main_quit'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|39|undefined reference tog_signal_connect_data'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|42|undefined reference to gtk_widget_show_all'| F:\Users\ROOT\Documents\codeblock\gfffnewaa\main.c|44|undefined reference togtk_main'| ||=== Build finished: 39 errors, 0 warnings (0 minutes, 1 seconds) ===|
要编译 GTK+ 应用程序,您需要告诉编译器在哪里可以找到 GTK+ 头文件和库。这是通过 pkg-config 实用程序完成的。
对于头文件,您需要在代码块选项中添加以下构建选项。
pkg-config --cflags gtk+-3.0
对于库,您需要在代码块选项中添加以下构建选项。
pkg-config --libs gtk+-3.0
请看一下对你有帮助。
我的问题是我使用了 gtk x64,但是代码块与 gtk x86
一起工作现在我使用 gtkx86 和 codeblock x86,效果很好。 有时现在有错误,只有我们感到困惑...