After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 768142 - Incorrect order of $(LIBS) and $(OBJS) in Makefile.example caused "undefined reference" error during linking
Incorrect order of $(LIBS) and $(OBJS) in Makefile.example caused "undefined ...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
unspecified
Other Linux
: Normal minor
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-06-28 14:40 UTC by Nathan Zhao
Modified: 2016-07-03 17:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
examples: Fix linker command in Makefile.example files (5.33 KB, patch)
2016-06-29 08:49 UTC, Nathan Zhao
none Details | Review

Description Nathan Zhao 2016-06-28 14:40:08 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).
Comment 1 Nathan Zhao 2016-06-29 08:49:05 UTC
Created attachment 330538 [details] [review]
examples: Fix linker command in Makefile.example files
Comment 2 Matthias Clasen 2016-06-30 03:20:14 UTC
It builds fine here. What is the error you are seeing ?
Comment 3 Nathan Zhao 2016-06-30 07:49:56 UTC
(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