1

I am trying to built some sample gtk+ examples that came with the gtk+ sources. My need was only to have a gtk+ UI to a C program. I went about downloading and building gtk+ but realised (through SO) that this was not needed and that I only need libgtk-3-dev.

sudo apt-get install libgtk-3-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libgtk-3-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 373 not upgraded.

EDIT: NOTE: Issue is not with the sequence of libraries or includes as I am using the makefile that came with gtk+.

I tried compiling an example that I had with the gtk+ code I downloaded. I get the below errors. The other queries on this topic mentioned that the order of the flags matter, but in this case I have used the makefile that came with the sources. Should I be installing something more than the libgtk-3-dev library (running on Ubuntu 14.04 ).

~/gtk/examples/application1$    make -f Makefile.example

cc -c -o main.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 main.c cc -c -o exampleapp.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 exampleapp.c cc -c -o exampleappwin.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 exampleappwin.c cc -o exampleapp -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 main.o exampleapp.o exampleappwin.o main.o: In function main': main.c:(.text+0x11): undefined reference tog_application_get_type' main.c:(.text+0x24): undefined reference to g_type_check_instance_cast' main.c:(.text+0x35): undefined reference tog_application_run' exampleapp.o: In function example_app_class_intern_init': exampleapp.c:(.text+0x14): undefined reference tog_type_class_peek_parent' exampleapp.c:(.text+0x36): undefined reference to g_type_class_adjust_private_offset' exampleapp.o: In functionexample_app_get_type': exampleapp.c:(.text+0x66): undefined reference to g_once_init_enter' exampleapp.c:(.text+0x84): undefined reference tog_intern_static_string' exampleapp.c:(.text+0x8c): undefined reference to gtk_application_get_type' exampleapp.c:(.text+0xb4): undefined reference tog_type_register_static_simple' exampleapp.c:(.text+0xc9): undefined reference to g_once_init_leave' exampleapp.o: In functionexample_app_activate': exampleapp.c:(.text+0x104): undefined reference to g_type_check_instance_cast' exampleapp.c:(.text+0x115): undefined reference togtk_window_get_type' exampleapp.c:(.text+0x127): undefined reference to g_type_check_instance_cast' exampleapp.c:(.text+0x12f): undefined reference togtk_window_present' exampleapp.o: In function example_app_open': exampleapp.c:(.text+0x14d): undefined reference togtk_application_get_type' exampleapp.c:(.text+0x15f): undefined reference to g_type_check_instance_cast' exampleapp.c:(.text+0x167): undefined reference togtk_application_get_windows' exampleapp.c:(.text+0x18c): undefined reference to g_type_check_instance_cast' exampleapp.c:(.text+0x1a9): undefined reference tog_type_check_instance_cast' exampleapp.c:(.text+0x1f5): undefined reference to gtk_window_get_type' exampleapp.c:(.text+0x207): undefined reference tog_type_check_instance_cast' exampleapp.c:(.text+0x20f): undefined reference to gtk_window_present' exampleapp.o: In functionexample_app_class_init': exampleapp.c:(.text+0x222): undefined reference to g_application_get_type' exampleapp.c:(.text+0x234): undefined reference tog_type_check_class_cast' exampleapp.c:(.text+0x244): undefined reference to g_application_get_type' exampleapp.c:(.text+0x256): undefined reference tog_type_check_class_cast' exampleapp.o: In function example_app_new': exampleapp.c:(.text+0x294): undefined reference tog_object_new' exampleappwin.o: In function example_app_window_class_intern_init': exampleappwin.c:(.text+0x14): undefined reference tog_type_class_peek_parent' exampleappwin.c:(.text+0x36): undefined reference to g_type_class_adjust_private_offset' exampleappwin.o: In functionexample_app_window_get_type': exampleappwin.c:(.text+0x66): undefined reference to g_once_init_enter' exampleappwin.c:(.text+0x84): undefined reference tog_intern_static_string' exampleappwin.c:(.text+0x8c): undefined reference to gtk_application_window_get_type' exampleappwin.c:(.text+0xb4): undefined reference tog_type_register_static_simple' exampleappwin.c:(.text+0xc9): undefined reference to g_once_init_leave' exampleappwin.o: In functionexample_app_window_new': exampleappwin.c:(.text+0x117): undefined reference to `g_object_new' collect2: error: ld returned 1 exit status make: *** [exampleapp] Error 1

user132797
  • 359
  • 5
  • 14
  • 1
    Ubuntu 14.04 only comes with GTK+ 3.10; you won't be able to build examples for newer versions of GTK+ with it. Get a version of the GTK+ 3.10 source code and the examples should build. – andlabs May 14 '16 at 19:23
  • Possible duplicate of [Why does the order in which libraries are linked sometimes cause errors in GCC?](http://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc) TL;DR move `main.o` in front of all `-lxxx`. – n. m. could be an AI May 14 '16 at 20:17
  • @n.m. They are trying to build an example that comes with the GTK+ source, not their own program. These examples have a correct makefile already. If that actually is the problem here, then these makefiles are broken... – andlabs May 14 '16 at 22:43
  • @andlabs : oops ! :( I overlooked that part which said the example came with gtk. Thanks for the time with my answer.. – sjsam May 15 '16 at 03:19
  • @andlabs, If you add this as an answer, I can accept it. I was able to configure gtk+ now which I was not able to earlier. The examples themselves do not have individual makefile like in gtk+ 3.20 but are built as a part of the configure. I have some modules (overlay-scrollbar, canberra-gtk-module, unity-gtk-module) that do not load when I run the built example but that is a different question I will post. I was curious to know how you figured I had the wrong version of GTK+ for 14.04. – user132797 May 15 '16 at 06:18
  • That was really more of an educated guess than anything, since a common problem is that people try to run newer GTK+ code than what their distro provides (and some of the symbols in the linker error log seemed to match up). I'm still concerned that those makefiles have `main.o` in the wrong order, though... I'll post an answer once I think of what to write about that. – andlabs May 15 '16 at 06:37
  • 1
    Makefile.example in the gtk+ tree is broken. – n. m. could be an AI May 16 '16 at 08:22

1 Answers1

1

For whatever reason the Makefile in the GTK+ 3.20 source tree is broken; as per n.m.'s comment. There might already be a bugfix, if not a fix, for that.

But you can't use GTK+ 3.20 with the GTK+ 3.10 that comes with Ubuntu 14.04 LTS. You're better off using the GTK+ 3.10 examples and source code. If you really want to use a newer version of GTK+, you can use jhbuild to set up an environment separate from the rest of the system (typically in /opt/gnome) to build a newer versions of GTK+ into.

andlabs
  • 11,290
  • 1
  • 31
  • 52
  • Based on your previous comment I did download gtk+3.10.9, the configure was successful. The make built the examples But it messed up my desktop environment & started getting a low graphics error. Had to uninstall through a make uninstall. – user132797 May 22 '16 at 07:21