Gcc: fatal error: gtk/gtk.h: No such file or directory

Hello, i was trying to compile a C file that includes:

 #include <gtk/gtk.h>

following this tutorial, but vs code gave me the error:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/home/teratron/Dev/c/games/tutorials/brickout/main.c).
cannot open source file "gtk/gtk.h"

plus it keeps adding gtk-3.0 before the include making it:

#include <gtk3.0/gtk/gtk.h>

trying to compile the file using gcc also doesn't work:

/Dev/c/games/tutorials/brickout$ gcc main.c Brickout
main.c:1:10: fatal error: gtk/gtk.h: No such file or directory
    1 | #include <gtk/gtk.h>
      |          ^~~~~~~~~~~
compilation terminated.

after some searching i found gtk isn't added to PATH, and i had more than one folder with "gtk" in its name :

1- (usr/include/gtk-3.0) this one has 3 sub folders:
                                 (/gdk, /gtk and /unix-print)
2- (usr/share/gtk-3.0)

i chose the first (usr/include/gtk-3.0) as it's the one that its gtk subfolder has the gtk.h header.

i added the path to $PATH by editing the file .bashrc adding to its bottom:

export PATH=$PATH:/usr/include/gtk-3.0

now i get the same error messages but with "gdk" instead of "gtk" from both vscode and gcc in the terminal, gdk.h is located in the subfolder gdk under gtk-3.0 that i already added to the $PATH variable.

now i didn't want to go ahead and add gdk.h to the path as well and see what else it says bc i felt maybe im not doing it right.

what should i do? isn't there one path to add to $PATH and it just works for all other gtk headers the gtk.h i included apparently calls?

What does vs code have to do with the tutorial? Are you following the tutorial exactly, as in compiling from the command line? That is my first thought.

Can you show the output from a command line invocation? Can you compile a simple hello world that prints to std out without the gtk include (i.e. #include )?

1 Like

hat does vs code have to do with the tutorial?

nothing, it's just the code editor i'm using

yeah every other thing doesn't cause errors and compiles from the command line perfectly

1 Like

From the gtk org website:


I would look at that.


it worked! but:

  1. is there a shorter way when compiling than writing this long command?
gcc `pkg-config --cflags gtk+-3.0` main.c `pkg-config --libs gtk+-3.0`

because i sure will be doing this hundred times a day

  1. vscode still screams with errors what can i do about it?
  1. Use the up arrow or a different tool for editing and compiling.

  2. Obviously, don't use vs code. I use Geany, it's in the boutique. Many others out there.

1 Like