I am making a simple program in C that uses glib.h , but when I compile it, I get an error, for example:
$ gcc test.c -o test test.c:3:18: fatal error: glib.h: No such file or directory compilation terminated.
So it seems that gcc cannot find the glib.h file (which is part of the libglib2.0-dev package and is already installed). So first I try to find the glib.h files on my system and find the output as shown 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 tried the 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 correct flags for GCC, but it also shows the same error.
So, try to find a solution from SO and find the exact solution, for example
$ gcc test.c -Wall -o test `pkg-config --cflags --libs glib-2.0`
this command solves my problem
But I have a question that I can not tell gcc to enable the glib library, so I do not need to specify the pkg-config --cflags --libs glib-2.0 flag after gcc and just compile my gcc test.c -o test file gcc test.c -o test ?
source share