GNOME Bugzilla – Bug 768142
Incorrect order of $(LIBS) and $(OBJS) in Makefile.example caused "undefined reference" error during linking
Last modified: 2016-07-03 17:57:40 UTC
In examples/application*/Makefile.example, the command for linking has $(LIBS) before $(OBJS), which caused "undefined reference" error: >== examples/application1/Makefile.example <== exampleapp: $(OBJS) $(CC) -o $(@F) $(LIBS) $(OBJS) To fix this, we need to put $(LIBS) behind $(OBJS).
Created attachment 330538 [details] [review] examples: Fix linker command in Makefile.example files
It builds fine here. What is the error you are seeing ?
(In reply to Matthias Clasen from comment #2) > It builds fine here. What is the error you are seeing ? Hi, I saw "undefined reference" errors of many gtk/glib functions, which I think is caused by the line below in Makefile.example: 16 $(CC) -o $(@F) $(LIBS) $(OBJS) Steps to reproduce: 1. cd examples/application1 && LANG=C make -f Makefile.example Output: 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 to `g_application_get_type' main.c:(.text+0x24): undefined reference to `g_type_check_instance_cast' main.c:(.text+0x35): undefined reference to `g_application_run' exampleapp.o: In function `example_app_class_intern_init': exampleapp.c:(.text+0x14): undefined reference to `g_type_class_peek_parent' exampleapp.c:(.text+0x36): undefined reference to `g_type_class_adjust_private_offset' exampleapp.o: In function `example_app_get_type': exampleapp.c:(.text+0x66): undefined reference to `g_once_init_enter' exampleapp.c:(.text+0x84): undefined reference to `g_intern_static_string' exampleapp.c:(.text+0x8c): undefined reference to `gtk_application_get_type' exampleapp.c:(.text+0xb4): undefined reference to `g_type_register_static_simple' exampleapp.c:(.text+0xc9): undefined reference to `g_once_init_leave' exampleapp.o: In function `example_app_activate': exampleapp.c:(.text+0x104): undefined reference to `g_type_check_instance_cast' exampleapp.c:(.text+0x115): undefined reference to `gtk_window_get_type' exampleapp.c:(.text+0x127): undefined reference to `g_type_check_instance_cast' exampleapp.c:(.text+0x12f): undefined reference to `gtk_window_present' exampleapp.o: In function `example_app_open': exampleapp.c:(.text+0x14d): undefined reference to `gtk_application_get_type' exampleapp.c:(.text+0x15f): undefined reference to `g_type_check_instance_cast' exampleapp.c:(.text+0x167): undefined reference to `gtk_application_get_windows' exampleapp.c:(.text+0x18c): undefined reference to `g_type_check_instance_cast' exampleapp.c:(.text+0x1a9): undefined reference to `g_type_check_instance_cast' exampleapp.c:(.text+0x1f5): undefined reference to `gtk_window_get_type' exampleapp.c:(.text+0x207): undefined reference to `g_type_check_instance_cast' exampleapp.c:(.text+0x20f): undefined reference to `gtk_window_present' exampleapp.o: In function `example_app_class_init': exampleapp.c:(.text+0x222): undefined reference to `g_application_get_type' exampleapp.c:(.text+0x234): undefined reference to `g_type_check_class_cast' exampleapp.c:(.text+0x244): undefined reference to `g_application_get_type' exampleapp.c:(.text+0x256): undefined reference to `g_type_check_class_cast' exampleapp.o: In function `example_app_new': exampleapp.c:(.text+0x294): undefined reference to `g_object_new' exampleappwin.o: In function `example_app_window_class_intern_init': exampleappwin.c:(.text+0x14): undefined reference to `g_type_class_peek_parent' exampleappwin.c:(.text+0x36): undefined reference to `g_type_class_adjust_private_offset' exampleappwin.o: In function `example_app_window_get_type': exampleappwin.c:(.text+0x66): undefined reference to `g_once_init_enter' exampleappwin.c:(.text+0x84): undefined reference to `g_intern_static_string' exampleappwin.c:(.text+0x8c): undefined reference to `gtk_application_window_get_type' exampleappwin.c:(.text+0xb4): undefined reference to `g_type_register_static_simple' exampleappwin.c:(.text+0xc9): undefined reference to `g_once_init_leave' exampleappwin.o: In function `example_app_window_new': exampleappwin.c:(.text+0x117): undefined reference to `g_object_new' collect2: error: ld returned 1 exit status make: *** [exampleapp] Error 1