Errors while trying to compile a libadwaita program

Hi, I’m new to gtk/libadwaita and try to build my first HelloWorld program. I took the source code from here: Adw – 1: Initialization (the first one…). In order to compile it I run this:

gcc $(pkg-config --cflags --libs gtk4) $(pkg-config --cflags --libs libadwaita-1) main.c -o main

But I get the errors below:

/usr/bin/ld: /tmp/ccQVxvvw.o: in function `glib_autoptr_clear_GtkApplication':
main.c:(.text+0x1b): undefined reference to `g_object_unref'
/usr/bin/ld: /tmp/ccQVxvvw.o: in function `activate_cb':
main.c:(.text+0x73): undefined reference to `gtk_application_window_new'
/usr/bin/ld: main.c:(.text+0x86): undefined reference to `gtk_label_new'
/usr/bin/ld: main.c:(.text+0x8f): undefined reference to `gtk_window_get_type'
/usr/bin/ld: main.c:(.text+0xa1): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: main.c:(.text+0xb6): undefined reference to `gtk_window_set_title'
/usr/bin/ld: main.c:(.text+0xbb): undefined reference to `gtk_window_get_type'
/usr/bin/ld: main.c:(.text+0xcd): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: main.c:(.text+0xdf): undefined reference to `gtk_window_set_default_size'
/usr/bin/ld: main.c:(.text+0xe4): undefined reference to `gtk_window_get_type'
/usr/bin/ld: main.c:(.text+0xf6): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: main.c:(.text+0x108): undefined reference to `gtk_window_set_child'
/usr/bin/ld: main.c:(.text+0x10d): undefined reference to `gtk_window_get_type'
/usr/bin/ld: main.c:(.text+0x11f): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: main.c:(.text+0x127): undefined reference to `gtk_window_present'
/usr/bin/ld: /tmp/ccQVxvvw.o: in function `main':
main.c:(.text+0x156): undefined reference to `adw_application_new'
/usr/bin/ld: main.c:(.text+0x185): undefined reference to `g_signal_connect_data'
/usr/bin/ld: main.c:(.text+0x18a): undefined reference to `g_application_get_type'
/usr/bin/ld: main.c:(.text+0x19c): undefined reference to `g_type_check_instance_cast'
/usr/bin/ld: main.c:(.text+0x1b0): undefined reference to `g_application_run'

What am I doing wrong? Thank you.

Additional information:

pkg-config --cflags --libs gtk4
-I/usr/include/gtk-4.0 -I/usr/include/pango-1.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/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/graphene-1.0 -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include -mfpmath=sse -msse -msse2 -pthread -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 
pkg-config --cflags --libs libadwaita-1
-I/usr/include/libadwaita-1 -I/usr/include/gtk-4.0 -I/usr/include/pango-1.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/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/graphene-1.0 -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include -mfpmath=sse -msse -msse2 -pthread -ladwaita-1 -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

This is not how you use pkg-config:

gcc \
  $(pkg-config --cflags --libs gtk4) \
  $(pkg-config --cflags --libs libadwaita-1) \
 main.c -o main

You should use:

gcc $(pkg-config --cflags libadwaita-1) -o main main.c $(pkg-config --libs libadwaita-1)

instead.

Which OS are you using? How did you install the various dependencies?

Thank you.
I used the command you said, and it really works, and there are no errors, but its opens the “Hello World” window with an old theme of libadwaita or gtk (the first image with square window corners):
image

In the second image you can see how the window should look like (on the left), with libadwaita.

(I’m using Debian 12 Bookworm [testing])

Thanks for helping me.

You are probably using the xorg session, so a window that doesn’t use a custom titlebar gets its decoration from the window manager.

1 Like

Thank you very much!

It indeed solved this problem…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.