Thread: Undefined reference when building gtk applications

  1. #1
    Registered User
    Join Date
    Sep 2019
    Posts
    10

    Undefined reference when building gtk applications

    Hello. I have been trying to build gimp from source. Yer, every time I execute configure, it fails with a message

    Code:
    *** Could not run GTK+ test program, checking why...
    *** The test program failed to compile or link. See the file config.log for the
    *** exact error that occured. This usually means GTK+ is incorrectly installed.
    configure: error: Test for GTK+ failed. See the file 'INSTALL' for help
    Looking into config.log, there is:
    Code:
    configure:28333: gcc -o conftest -g -O2 -Wall -Wdeclaration-after-statement -Wmissing-prototypes -Wmissing-declarations -Winit-self -Wpointer-arith -Wold-style-definition  -I/media/34GB/Arquivos-de-Programas-Linux/xorg/X11-1.4.4/include -I/media/34GB/Arquivos-de-Programas-Linux/xorg/Xorgproto-2018.1/include/ -I/media/34GB/Arquivos-de-Programas-Linux/Gtk+-2.24.20/include/gtk-2.0/ -I/media/34GB/Arquivos-de-Programas-Linux/Glib-2.32.0/include/glib-2.0/ -I/media/34GB/Arquivos-de-Programas-Linux/Glib-2.32.0/lib/glib-2.0/include/ -I/media/34GB/Arquivos-de-Programas-Linux/Cairo-1.10.0/include/cairo/ -I/media/34GB/Arquivos-de-Programas-Linux/Pango-1.30.0/include/pango-1.0/ -I/media/34GB/Arquivos-de-Programas-Linux/Gtk+-2.24.20/lib/gtk-2.0/include/ -I/media/34GB/Arquivos-de-Programas-Linux/Gdk-pixbuf-2.25.2/include/gdk-pixbuf-2.0/ -I/media/34GB/Arquivos-de-Programas-Linux/Atk-2.15.4/include/atk-1.0/ -L/media/34GB/Arquivos-de-Programas-Linux/xorg/X11-1.4.4/lib/ conftest.c   >&5
    conftest.c: In function 'main':
    conftest.c:50:1: warning: old-style function definition [-Wold-style-definition]
     main ()
     ^
    /usr/bin/ld: Dwarf Error: found dwarf version '4', this reader only handles version 2 and 3 information.
    /tmp/ccB33dRl.o: In function `main':
    conftest.c:(.text.startup+0x2): undefined reference to `gtk_major_version'
    /usr/bin/ld: Dwarf Error: found dwarf version '0', this reader only handles version 2 and 3 information.
    conftest.c:(.text.startup+0x11): undefined reference to `gtk_minor_version'
    /usr/bin/ld: Dwarf Error: found dwarf version '315', this reader only handles version 2 and 3 information.
    conftest.c:(.text.startup+0x1c): undefined reference to `gtk_micro_version'
    collect2: error: ld returned 1 exit status
    configure:28339: $? = 1
    configure: failed program was:
    | /* confdefs.h.  */
    | #define PACKAGE_NAME "GIMP"
    | #define PACKAGE_TARNAME "gimp"
    | #define PACKAGE_VERSION "2.6.0"
    | #define PACKAGE_STRING "GIMP 2.6.0"
    | #define PACKAGE_BUGREPORT "http://bugzilla.gnome.org/enter_bug.cgi?product=GIMP"
    | #define GETTEXT_PACKAGE "gimp20"
    | #define STDC_HEADERS 1
    | #define HAVE_SYS_TYPES_H 1
    | #define HAVE_SYS_STAT_H 1
    | #define HAVE_STDLIB_H 1
    | #define HAVE_STRING_H 1
    | #define HAVE_MEMORY_H 1
    | #define HAVE_STRINGS_H 1
    | #define HAVE_INTTYPES_H 1
    | #define HAVE_STDINT_H 1
    | #define HAVE_UNISTD_H 1
    | #define HAVE_DLFCN_H 1
    | #define ARCH_X86 1
    | #define ARCH_X86_64 1
    | #define STDC_HEADERS 1
    | #define HAVE_SYS_WAIT_H 1
    | #define TIME_WITH_SYS_TIME 1
    | #define HAVE_SYS_PARAM_H 1
    | #define HAVE_SYS_TIME_H 1
    | #define HAVE_SYS_TIMES_H 1
    | #define HAVE_SYS_WAIT_H 1
    | #define HAVE_UNISTD_H 1
    | #define RETSIGTYPE void
    | #define HAVE_VPRINTF 1
    | #define HAVE_ALLOCA_H 1
    | #define HAVE_ALLOCA 1
    | #define HAVE_DIFFTIME 1
    | #define HAVE_MMAP 1
    | #define HAVE__NL_MEASUREMENT_MEASUREMENT 1
    | #define HAVE_LOCALE_H 1
    | #define HAVE_LC_MESSAGES 1
    | #define HAVE_BIND_TEXTDOMAIN_CODESET 1
    | #define HAVE_GETTEXT 1
    | #define HAVE_DCGETTEXT 1
    | #define ENABLE_NLS 1
    | #define HAVE_ISO_CODES 1
    | #define HAVE_BIND_TEXTDOMAIN_CODESET 1
    | /* end confdefs.h.  */
    | 
    | #include <gtk/gtk.h>
    | #include <stdio.h>
    | 
    | int
    | main ()
    | {
    |  return ((gtk_major_version) || (gtk_minor_version) || (gtk_micro_version));
    |   ;
    |   return 0;
    | }
    configure:28370: error: Test for GTK+ failed. See the file 'INSTALL' for help.
    Then I tried to build this test by my own:

    Code:
    #include <gtk/gtk.h>
     #include <stdio.h>
     
     int
     main ()
     {
      return ((gtk_major_version) || (gtk_minor_version) || (gtk_micro_version));
       ;
       return 0;
     }
    with
    Code:
    gcc -o conftest2 -I /media/34GB/Arquivos-de-Programas-Linux/Gtk+-2.24.20/include/gtk-2.0/ -I /media/34GB/Arquivos-de-Programas-Linux/Cairo-1.10.0/include/cairo/ -I /media/34GB/Arquivos-de-Programas-Linux/Glib-2.32.0/include/glib-2.0/ -I /media/34GB/Arquivos-de-Programas-Linux/Glib-2.32.0/lib/glib-2.0/include/ -I /media/34GB/Arquivos-de-Programas-Linux/Pango-1.30.0/include/pango-1.0/ -I /media/34GB/Arquivos-de-Programas-Linux/Gtk+-2.24.20/lib/gtk-2.0/include/ -I /media/34GB/Arquivos-de-Programas-Linux/Atk-2.15.4/include/atk-1.0/ -I /media/34GB/Arquivos-de-Programas-Linux/Gdk-pixbuf-2.25.2/include/gdk-pixbuf-2.0/ conftest2.c
    and received:
    Code:
    /tmp/ccCdzV54.o: In function `main':
    conftest2.c:(.text+0x6): undefined reference to `gtk_major_version'
    conftest2.c:(.text+0x10): undefined reference to `gtk_minor_version'
    conftest2.c:(.text+0x1a): undefined reference to `gtk_micro_version'
    collect2: error: ld returned 1 exit status
    I tried to check if the system gtk had these
    gtk_whatever_version
    on it and executed:

    Code:
    nm -s /usr/lib/libgtk-x11-2.0.so.0.2000.0 | grep gtk_major_version
    that returned:
    nm: /usr/lib/libgtk-x11-2.0.so.0.2000.0: no symbols
    I then tested with my two own built libgtk:

    Code:
     nm -s /media/34GB/Arquivos-de-Programas-Linux/Gtk+-2.24.20/lib/libgtk-x11-2.0.so.0.2400.20 | grep gtk_major_version
    that returned
    Code:
    0000000000344f64 R gtk_major_version
    and
    Code:
    nm -s /media/34GB/Arquivos-de-Programas-Linux-32bit/Gtk+-2.12.0/lib/libgtk-x11-2.0.so.0.1200.0 | grep gtk_major_version
    that returned:

    Code:
    003821c0 R gtk_major_version
    Then I did my last attempts, tried to build the conftest example using my own gtks (-L added).

    Code:
    gcc -o conftest2 -I /media/34GB/Arquivos-de-Programas-Linux/Gtk+-2.24.20/include/gtk-2.0/ -I /media/34GB/Arquivos-de-Programas-Linux/Cairo-1.10.0/include/cairo/ -I /media/34GB/Arquivos-de-Programas-Linux/Glib-2.32.0/include/glib-2.0/ -I /media/34GB/Arquivos-de-Programas-Linux/Glib-2.32.0/lib/glib-2.0/include/ -I /media/34GB/Arquivos-de-Programas-Linux/Pango-1.30.0/include/pango-1.0/ -I /media/34GB/Arquivos-de-Programas-Linux/Gtk+-2.24.20/lib/gtk-2.0/include/ -I /media/34GB/Arquivos-de-Programas-Linux/Atk-2.15.4/include/atk-1.0/ -I /media/34GB/Arquivos-de-Programas-Linux/Gdk-pixbuf-2.25.2/include/gdk-pixbuf-2.0/ -L /media/34GB/Arquivos-de-Programas-Linux/Gtk+-2.24.20/lib/ conftest2.c
    and

    Code:
    gcc -m32 -o conftest2 -I /media/34GB/Arquivos-de-Programas-Linux-32bit/Gtk+-2.12.0/include/gtk-2.0/ -I /media/34GB/Arquivos-de-Programas-Linux-32bit/Cairo-1.2.6/include/cairo/ -I /media/34GB/Arquivos-de-Programas-Linux-32bit/Glib-2.20.0/include/glib-2.0/ -I /media/34GB/Arquivos-de-Programas-Linux-32bit/Glib-2.20.0/lib/glib-2.0/include/ -I /media/34GB/Arquivos-de-Programas-Linux-32bit/Pango-1.20.5/include/pango-1.0/ -I /media/34GB/Arquivos-de-Programas-Linux-32bit/Gtk+-2.12.0/lib/gtk-2.0/include/ -I /media/34GB/Arquivos-de-Programas-Linux-32bit/Atk-1.29.2/include/atk-1.0/ -L /media/34GB/Arquivos-de-Programas-Linux-32bit/Gtk+-2.12.0/lib/  conftest2.c
    Both returned:

    Code:
    conftest2.c:(.text+0x4): undefined reference to `gtk_major_version'
    conftest2.c:(.text+0xd): undefined reference to `gtk_minor_version'
    conftest2.c:(.text+0x16): undefined reference to `gtk_micro_version'
    So, any suggestions as to why this is happening?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,461
    All your command lines are missing one or more -l options

    -L (uppercase) tells the linker where to look for libraries
    -l (lowercase) tells the linker the names of libraries to examine.

    If your actual library name is libfoo.a or libfoo.so, you say -lfoo on the command line.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,163
    Random guess you are missing the GTL devel packages that contains the GTK headers.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. undefined reference to ...
    By DeletedUserAccount in forum C Programming
    Replies: 16
    Last Post: 01-28-2011, 02:27 PM
  2. Undefined reference ?
    By Holymanus in forum C Programming
    Replies: 6
    Last Post: 01-07-2011, 09:15 AM
  3. Undefined reference?
    By Tirith in forum C Programming
    Replies: 8
    Last Post: 08-11-2009, 02:39 PM
  4. undefined reference....
    By najwani in forum C Programming
    Replies: 0
    Last Post: 04-06-2009, 10:05 PM
  5. undefined reference
    By B_Love in forum C++ Programming
    Replies: 6
    Last Post: 09-26-2005, 08:13 AM

Tags for this Thread