1

I'm running Ubuntu 21.10 and have installed build-essential, libgtk-4-dev and Gnome Builder as IDE. I'm starting with a basic tutorial that starts out #include <gtk/gtk.h> but it gives the error:

1:10: error: 'gtk/gtk.h' file not found

I read somewhere that it should be in /usr/include/ but when I looked I found it was at /usr/include/gtk-4.0/gtk/gtk.h

What's the best way to set up my system so that the default include line works? I read https://askubuntu.com/questions/1374329/how-to-compile-a-gtk4-application-in-ubuntu-21-10 but his fix was installing libgtk-4-dev which I've already done. I thought of creating a symlink from /usr/include/gtk-4.0/gtk/gtk.h to /usr/include/ but that seems like a rabbit hole I shouldn't go down. I'm stuck before I even got started! Any help appreciated.

CraigFoote
  • 371
  • 1
  • 7
  • 23
  • 1
    Stop trying to get compilation to work without any flags. Even if you got compilation to work without flags, you are definitely going to need to add linker flags. Better to just do it right from the beginning. If you're creating a new project I'd suggest using Meson for the build system, which should integrate quite well with GNOME Builder. – nemequ Feb 23 '22 at 16:26

1 Answers1

2

Per the official C documentation on compiling programs with GTK4 on Unix you need to run pkg-config with the requisite paths before running the compiler:

Include:

$ pkg-config --cflags gtk4 -pthread -I/usr/include/gtk-4.0 \
    -I/usr/lib64/gtk-4.0/include -I/usr/include/cairo \
    -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 \
    -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 \
    -I/usr/include/freetype2 -I/usr/include/libpng12

Libraries:

$ pkg-config --libs gtk4 -pthread -lgtk-4 -lgdk-4 -lgio-2.0 \
    -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo \
    -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 \
    -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0

Compile:

$ cc `pkg-config --cflags gtk4` hello.c -o hello `pkg-config --libs gtk4`

Make sure to replace cc with your respective compiler and hello with your source file and desired executable name. Also you may need to remove the -pthread flags.

tryptic
  • 21
  • 2