I'm trying to run the "Hello World" example from the official GTK documentation:
GTK Hello World Example
I followed the instructions and ran the following command:
gcc $(pkg-config --cflags gtk4) -o hello-world-gtk hello-world-gtk.c $(pkg-config --libs gtk4)
However, I got this error:
hello-world-gtk.c:1:10: fatal error: gtk/gtk.h: No such file or directory
1 | #include <gtk/gtk.h>
| ^~~~~~~~~~~
compilation terminated.
I have GTK4 installed, and the directory /usr/include/gtk-4.0/gtk
exists, so the file gtk.h
is present. It seems like GCC can't find the library despite using pkg-config
.
Additional Information:
System: Arch Linux, kernel version
6.11.9-arch1-1
Installed GTK version:
gtk4
(confirmed viapacman -Q gtk4
)pkg-config
seems to work when I test it:pkg-config --cflags gtk4
Outputs something like:
-I/usr/include/gtk-4.0
Similarly,
pkg-config --libs gtk4
outputs the correct linker flags.
Despite all this, GCC still can't find the header.
- Verified the
gtk.h
file exists in/usr/include/gtk-4.0/gtk
. - Reinstalled
gtk4
andpkg-config
viapacman
. - Checked that
pkg-config
outputs the correct flags (as shown above).
What might I be missing, and how can I fix this issue?
(btw. clangd has the same issue and prints tons of errors because it cant find the library)
Here some additional log based on the comments:
gtk.h
exists and is accessible:
The file/usr/include/gtk-4.0/gtk/gtk.h
is present and readable:.rw-r--r-- 11k root 1 Nov 20:21 /usr/include/gtk-4.0/gtk/gtk.h
Expanded compilation command:
The full command generated bypkg-config
is:gcc -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/graphene-1.0 -I/usr/lib/graphene-1.0/include -mfpmath=sse -msse -msse2 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/sysprof-6 -pthread -I/usr/include/libpng16 -I/usr/include/pixman-1 -o hello-world-gtk hello-world-gtk.c -lgtk-4 -lharfbuzz -lpangocairo-1.0 -lpango-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lvulkan -lgraphene-1.0 -lgio-2.0 -lglib-2.0 -lgobject-2.0
Direct
-I
flag:
Attempting to compile with-I/usr/include/gtk-4.0
results in:fatal error: glib.h: No such file or directory
Output of
pkg-config
:
pkg-config --cflags gtk4
correctly includes:-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
Environment variable check:
PKG_CONFIG_PATH
is empty, so there should be no interference:echo $PKG_CONFIG_PATH (no output)
Output of
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl= --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20240910 (GCC)
- Output of
pacman -Qi gcc
Name : gcc
Version : 14.2.1+r134+gab884fffe3fc-1
Description : The GNU Compiler Collection - C and C++ frontends
Architecture : x86_64
URL :
Licenses : GPL-3.0-with-GCC-exception GFDL-1.3-or-later
Groups : None
Provides : gcc-multilib
Depends On : gcc-libs=14.2.1+r134+gab884fffe3fc-1 binutils>=2.28 libmpc
zstd libisl.so=23-64
Optional Deps : lib32-gcc-libs: for generating code for 32-bit ABI
Required By : base-devel clang dmd rust vala
Optional For : dmd node-gyp x-xrdb
Conflicts With : None
Replaces : gcc-multilib
Installed Size : 202,47 MiB
Packager : Frederik Schwan <[email protected]>
Build Date : 2024-09-10T15:07:33 CEST
Install Date : 2024-11-09T22:09:28 CET
Install Reason : Installed as a dependency for another package
Install Script : No
Validated By : Signature