2

I am trying to use gui with gkt-2.0 in Linux mint 32bit. When I try to compile gui.c I encountered following error message:

#include<gtk-2.0/gtk/gtk.h>

void main(){
}
In file included from gui.c:1:0:
/usr/include/gtk-2.0/gtk/gtk.h:32:10: fatal error: gdk/gdk.h: No such file or directory
 #include <gdk/gdk.h>
          ^~~~~~~~~~~
Anonymous
  • 318
  • 4
  • 14
  • 1
    How do you compile? What command line options do you pass to the compiler? What include folders? Did you install required libs, i.e. is the header `gdk.h` available on your machine? – Gerhardh Dec 06 '21 at 08:39
  • gcc gui.c -o gui – Anonymous Dec 06 '21 at 08:39
  • /usr/include/gtk-2.0 this directory contains both gtk.h and gdk.h but in different folder. – Anonymous Dec 06 '21 at 08:40
  • 1
    You must tell your compiler where to look for headers of additional libraries. Also you must tell your linker to include those libraries. Any tutorial about GTK should tell you how to do it. – Gerhardh Dec 06 '21 at 08:56

1 Answers1

4

When the appropriate packages are installed, you can add the needed include search directories with option -I, and the libraries of course -l, e.g.

gcc -I/usr/include/gtk-2.0 gui.c -o gui -lgtk-2.0

The source should be changed to

#include <gtk/gtk.h>

To avoid hard-coding any paths and names, you could use pkg-config (Compiling GTK Applications on UNIX)

gcc $(pkg-config --cflags gtk+-3.0) gui.c -o gui $(pkg-config --libs gtk+-3.0)

Better yet, use make or some other build tool.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198