How to fix ‘Make’ error – glib.h no such file or directory

Question: When I try to build an application on Ubuntu, I'm getting the following error: 'Make' error - glib.h no such file or directory. How can I fix this error?

glib.h is part of "libglib2.0-dev" package. So make sure to install this package.

$ sudo apt-get install libglib2.0-dev

If that does not solve the problem, it may be because the application you are building expects glib development files in a different directory. In that case, you will need to manually specify information about glib-2.0 library in your Makefile. To find out what information to add to Makefile, you can use pkg-config command, which automatically finds metadata about installed libraries.

Run the following command, and put the output of the command in your Makefile.

$ pkg-config --cflags --libs glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include  -lglib-2.0

In this example, the command returns the above string. So in this case, I will specify "-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include" and "-lglib-2.0" somewhere in my Makefile.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

Leave a comment

Your email address will not be published. Required fields are marked *