You are not logged in.

#1 2012-09-21 16:01:27

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

[SOLVED] Suddenly can't compile program, glib.h can't be found.

Hey,

I'm in the process of refining the code of my first project and whilst doing so, making a basic Makefile so people using other distro's can use it as well. I haven't change any of the code, just removed some empty lines and fixed the outlining, so the error can't be in the code itself (confirmed by using the old version that's still on GitHub).

I have made a basic Makefile:

mpd-notify: mpd-notify.c
    gcc -o mpd-notify mpd-notify.c -lX11 -lmpdclient -lnotify

clean:
    rm mpd-notify

But when running make, I get the following error message:

┌─[jente @ lappy mpd-notify] 17:56:29 
└─■ make
gcc -o mpd-notify mpd-notify.c -lX11 -lmpdclient -lnotify
In file included from mpd-notify.c:15:0:
/usr/include/libnotify/notify.h:25:18: fatal error: glib.h: No such file or directory
compilation terminated.
make: *** [mpd-notify] Error 1

I have declared the following in my program:

#include <mpd/client.h>
#include <libnotify/notify.h>

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

Why is this suddenly happening? It built fine before on 30-08-2012

Last edited by Unia (2012-09-21 20:13:56)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#2 2012-09-21 18:15:18

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

I have done some more research and discovered that the glib.h file belongs to glib2. I do have the file (in /usr/include/glib-2.0/glib.h) and reinstalling glib2 didn't help.

What is wrong with my system?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#3 2012-09-21 18:27:36

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,476
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

I don't know why it was working but now it isn't. I am skeptical that you had "/usr/include/glib-2.0" in your default path of included files before it broke though. The "pkg-config" command helps with that.

Does the information in this thread help? http://ubuntuforums.org/showthread.php?t=1945240

Offline

#4 2012-09-21 18:43:17

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

drcouzelis wrote:

I don't know why it was working but now it isn't. I am skeptical that you had "/usr/include/glib-2.0" in your default path of included files before it broke though. The "pkg-config" command helps with that.

Does the information in this thread help? http://ubuntuforums.org/showthread.php?t=1945240

Hm, that does seem to help. I then get a missing dep of gdk-pixbuf, which in turn requires gtk (yes, gtk 1!). I guess something is wrong with the notify part. I don't know why though, it's the same as it was.

Here's the part of the PKGBUILD that I'm trying to make into a Makefile:

gcc -DPROGNAME="\"${pkgname}\"" -DVERSION="\"${pkgver}-${pkgrel}\"" -DDATE="\"`date -u`\"" \
    `pkg-config --cflags --libs libmpdclient` \
    `pkg-config --cflags --libs libnotify` \
    ${pkgname}.c -o ${pkgname}

My Makefile:

mpd-notify: mpd-notify.c
    gcc -o mpd-notify mpd-notify.c -lX11 -lmpdclient -lnotify

clean:
    rm mpd-notify

If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#5 2012-09-21 18:47:49

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,476
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

Waaait a minute... Are you trying to convert a working PKGBUILD file into a Makefile?

If that's the case, just copy what's in the PKGBUILD file but replace any variables (anything inside "${____}").

Offline

#6 2012-09-21 18:50:10

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

drcouzelis wrote:

Waaait a minute... Are you trying to convert a working PKGBUILD file into a Makefile?

If that's the case, just copy what's in the PKGBUILD file but replace any variables (anything inside "${____}").

But AFAIK, this: `pkg-config --cflags --libs libnotify` isn't supposed to be in a Makefile. I thought I could do like this too: -lnotify.

Am I wrong?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#7 2012-09-21 19:24:26

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,476
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

Oh, "pkg-config" is wonderful in a Makefile! For an example, here's one of mine: http://qogreatness.git.sourceforge.net/ … 4d;hb=HEAD

"pkg-config" allows a compiler to find files even if they're installed in non-standard locations. This way, you don't have to "hard code" your Makefile. smile

Offline

#8 2012-09-21 19:30:22

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

drcouzelis wrote:

Oh, "pkg-config" is wonderful in a Makefile! For an example, here's one of mine: http://qogreatness.git.sourceforge.net/ … 4d;hb=HEAD

"pkg-config" allows a compiler to find files even if they're installed in non-standard locations. This way, you don't have to "hard code" your Makefile. smile

Okay. It indeed works when using pkg-config, but just for reference; what would be the correct way to do this, without using pkg-config?


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#9 2012-09-21 19:46:24

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,476
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

Unia wrote:

It indeed works when using pkg-config, but just for reference; what would be the correct way to do this, without using pkg-config?

Well, the "correct" way is to use pkg-config. wink

Do you understand what the "pkg-config" command is doing? Just copy it into a terminal window. For example:

pkg-config --cflags glib-2.0

shows

-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include

In your Makefile, just delete the entire "pkg-config" command and replace it with the output from the terminal window and it will compile.

...But I still recommend using "pkg-config" in the Makefile! big_smile

Offline

#10 2012-09-21 19:53:52

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

So I could better use one pkg-config string, instead of specifying some statically (-lX11) and some with pkg-config?

(I just tried X11 with pkg-config but it couldn't find it. Does this mean I have to define some static and some with pkg-config? EDIT: Also, iw doesn't get found either. These come from -lX11 and -liw)

Is there some sort of README I can see which explains all this? tongue

Last edited by Unia (2012-09-21 19:56:40)


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#11 2012-09-21 20:07:17

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 3,476
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

The Wikipedia article on pkg-config is fine. The simple rule is to use pkg-config if the library has a ".pc" file in "/usr/lib/pkgconfig", otherwise just add the library to your "gcc" command by hand. Even X11 (your example) can be used with pkg-build. smile

Offline

#12 2012-09-21 20:13:41

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,471
Website

Re: [SOLVED] Suddenly can't compile program, glib.h can't be found.

drcouzelis wrote:

The Wikipedia article on pkg-config is fine. The simple rule is to use pkg-config if the library has a ".pc" file in "/usr/lib/pkgconfig", otherwise just add the library to your "gcc" command by hand. Even X11 (your example) can be used with pkg-build. smile

Got it! I will read the article and think I'm good to go then. For now, the Makefiles I need are simple tongue


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

Board footer

Powered by FluxBB