OS windows 10, Code :: Blocks 17.12, GTK + -> msys2-x86_64-20161025.exe

1-Создаю проект по шаблону GTK+ 2-Компиляция проходит успешно 3-Сборка выдает ошибки: ||=== Сборка: Debug in g2 (compiler: GNU GCC Compiler) ===| obj\Debug\main.o||In function `helloWorld':| C:\Work\g2\main.c|8|undefined reference to `gtk_window_get_type'| C:\Work\g2\main.c|8|undefined reference to `g_type_check_instance_cast'| C:\Work\g2\main.c|8|undefined reference to `gtk_message_dialog_new'| ...................... C:\Work\g2\main.c|46|undefined reference to `gtk_widget_show_all'| C:\Work\g2\main.c|47|undefined reference to `gtk_main'| ||error: ld returned 1 exit status| ||=== Build неудачно: 47 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===| 

I assume there is no correspondence between the C :: B template and the gtk + set. I tried various types of configuration, but my understanding is clearly not enough. Help to understand and create a minimal template with the included .glade file

Something like:

 #include<gtk/gtk.h> int main(int argc, char *argv[]){ GtkBuilder *gtkBuilder; GtkWidget *window; gtk_init(&argc, &argv); gtkBuilder = gtk_builder_new(); gtk_builder_add_from_file(gtkBuilder, "testGlade.glade", NULL); window = GTK_WIDGET(gtk_builder_get_object(gtkBuilder, "mywindow")); g_object_unref(G_OBJECT(gtkBuilder)); gtk_widget_show(window); gtk_main(); return 0; } 
  • one
    see link flags ... add -lgtk -lglib so on, and also probably -L/path/to/libs ... where exactly they are written in Blocks and how exactly to find out the full list on win (on nix ' Ah done with pkg-config ) - I will not tell you ... - Fat-Zer
  • If complete despair sets in, and if there is a familiar line, execute the command there: pkg-config --libs gtk + -3.0 and list the resulting libraries with the -l flag for your build. - Sergey

1 answer 1

You need to link to gtk3 - in GNU / Linux, use the pkg-config --libs --cflags gtk+-3.0 , the result of which is passed to the compiler. Apparently, you are using MinGW - install pkg-config and configure codeblocks to use it.

  • I executed the pkg-config --cflags gtk+-3.0 compilation configuration command pkg-config --cflags gtk+-3.0 and the pkg-config --libs gtk+-3.0 link configuration command pkg-config --libs gtk+-3.0 . Created a simple GTK3 window project - VladSlk
  • || === Build: Debug in gtk1 (compiler: GNU GCC Compiler) === | ld.exe || cannot find -ldwmapi | || error: ld returned 1 exit status | || === Build failed: 2 error (s), 0 warning (s) (0 minute (s), 0 second (s)) === | - VladSlk