I make simple program in C which uses glib.h
, but when I compile it I get an error like:
$ gcc test.c -o test
test.c:3:18: fatal error: glib.h: No such file or directory
compilation terminated.
So from above it seems gcc can't find glib.h
file (which is a part of the libglib2.0-dev
package and have already installed it). So first I try locate glib.h
files in my system and found output as below:
$ locate glib.h
/usr/src/linux-headers-3.2.0-29-generic-pae/include/config/blk/dev/bsglib.h
/usr/src/linux-headers-3.2.0-48-generic-pae/include/config/blk/dev/bsglib.h
/usr/src/linux-headers-3.2.0-57-generic-pae/include/config/blk/dev/bsglib.h
then I have tried command:
$ pkg-config --cflags glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include
to get the right flags for GCC but still it show same error.
So have try to find solution from SO and found exact solution like
$ gcc test.c -Wall -o test `pkg-config --cflags --libs glib-2.0`
this command solve my problem
But I have question that, is not any way to tell gcc include glib library so not require to give flag pkg-config --cflags --libs glib-2.0
after gcc
and simply I compile my file by gcc test.c -o test
?