title: "undefined reference to gtk..." when using Autotools for my C program
body: <p>The problem is I struggle to make the Autotools work with my C program. I am stuck getting the errors &quot;undefined reference to...&quot;.</p>
  <p>I work on Ubuntu 20.04.1 LTS.</p>
  <p>I am using:</p>
  <ul>
  <li>Xml glade file</li>
  <li>Css file</li>
  <li>stdlib.h</li>
  <li>gtk/gtk.h (v3)</li>
  <li>glib.h</li>
  <li>stdbool.h</li>
  </ul>
  <p>The hierarchy is:</p>
  <pre><code>main.c
  Makefile.am
  configure.ac
    /src
      structures.h
      /features
        timer.c
        timer.h
      /frontend
        frontend.c
        frontend.h
        style.css
        view.glade
      /signals
        options.c
        options.h
        timer_buttons.c
        timer_buttons.h
  </code></pre>
  <p>I successfully compile the program using:</p>
  <blockquote>
  <p>gcc-9 `pkg-config --cflags gtk+-3.0` -o main main.c `pkg-config --libs gtk+-3.0` -rdynamic -g -Wall</p>
  </blockquote>
  <p>It’s when I want to make a makefile using the autotools that I need a bit of help.</p>
  <p>Configure.ac</p>
  <pre><code>AC_INIT([main], [0.1])
  AM_INIT_AUTOMAKE([foreign subdir-objects -Wall])
  AC_PROG_CC
  AC_CONFIG_FILES([Makefile])
  PKG_CHECK_MODULES([GTK], [&quot;gtk+-3.0&quot;])
  AC_OUTPUT
  </code></pre>
  <p>Makefile.am</p>
  <pre><code>bin_PROGRAMS = main
  main_SOURCES = main.c
  main_CPPFLAGS = $(GTK_CFLAGS)
  main_LDFLAGS = $(GTK_LIBS)
  </code></pre>
  <p>Then I do the following:</p>
  <blockquote>
  <p>autoconf</p>
  </blockquote>
  <blockquote>
  <p>automake</p>
  </blockquote>
  <blockquote>
  <p>./configure</p>
  </blockquote>
  <pre><code>checking for a BSD-compatible install... /usr/bin/install -c
  checking whether build environment is sane... yes
  checking for a thread-safe mkdir -p... /bin/mkdir -p
  checking for gawk... no
  checking for mawk... mawk
  checking whether make sets $(MAKE)... yes
  checking whether make supports nested variables... yes
  checking for gcc... gcc
  checking whether the C compiler works... yes
  checking for C compiler default output file name... a.out
  checking for suffix of executables... 
  checking whether we are cross compiling... no
  checking for suffix of object files... o
  checking whether we are using the GNU C compiler... yes
  checking whether gcc accepts -g... yes
  checking for gcc option to accept ISO C89... none needed
  checking whether gcc understands -c and -o together... yes
  checking whether make supports the include directive... yes (GNU style)
  checking dependency style of gcc... gcc3
  checking for pkg-config... /usr/bin/pkg-config
  checking pkg-config is at least version 0.9.0... yes
  checking for GTK... yes
  checking that generated files are newer than configure... done
  configure: creating ./config.status
  config.status: creating Makefile
  config.status: executing depfiles commands
  </code></pre>
  <blockquote>
  <p>make</p>
  </blockquote>
  <pre><code>gcc  -g -O2 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0  -o main main-main.o  
  /usr/bin/ld: main-main.o: in function `run_timer':
  /home/myname/Desktop/project/src/features/timer.c:46: undefined reference to `gtk_label_get_type'
  /usr/bin/ld: /home/myname/Desktop/project/src/features/timer.c:46: undefined reference to `g_type_check_instance_cast'
  /usr/bin/ld: /home/myname/Desktop/project/src/features/timer.c:46: undefined reference to `gtk_label_set_text'
  /usr/bin/ld: main-main.o: in function `stick_checkbox_signal':
  /home/myname/Desktop/project/src/signals/options.c:6: undefined reference to `gtk_toggle_button_get_active'
  /usr/bin/ld: main-main.o: in function `start_signal':
  /home/myname/Desktop/project/src/signals/timer_buttons.c:11: undefined reference to `g_timeout_add'
  /usr/bin/ld: main-main.o: in function `pause_signal':
  /home/myname/Desktop/project/src/signals/timer_buttons.c:17: undefined reference to `g_source_remove'
  /usr/bin/ld: main-main.o: in function `reset_signal':
  /home/myname/Desktop/project/src/signals/timer_buttons.c:26: undefined reference to `g_source_remove'
  
  ###
  etc.............
  ###
  
  collect2: error: ld returned 1 exit status
  make: *** [Makefile:364: main] Error 1
  </code></pre>
  <p>You can see that I get these &quot;undefined reference to...&quot; errors. How do I make it work? I have been looking this up on internet quite a lot but I'm stuck here.</p>