Jesse Zhu
Jesse Zhu

Reputation: 131

How to fix "Error: Only <glib.h> can be included directly."

Under Linux Mint, trying make gnome-vfs-2.0.4, but I got the error messages:

/glib-2.0/glib/gtypes.h:31:2: error: #error "Only glib.h can be included directly."

glib-2.0/glib/gmacros.h:35:2: error: #error "Only glib.h can be included directly."

glib-2.0/glib/gversionmacros.h:31:2: error: #error "Only glib.h can be included directly."

glib-2.0/glib/glist.h:31:2: error: #error "Only  glib.h can be included directly."

glib-2.0/glib/gmem.h:31:2: error: #error "Only glib.h can be included directly."

glib-2.0/glib/gnode.h:31:2: error: #error "Only glib.h can be included directly."

I google it, and it is said I should change #include <glib/xxx.h> to #include <glib.h>, but more errors occur after I do so.

How to fix it?

Upvotes: 1

Views: 7583

Answers (1)

ebassi
ebassi

Reputation: 8805

why are you trying to compile a long since deprecated library like gnome-vfs? also, why are you trying to compile gnome-vfs 2.0.4, which is 11 years old, using a version of GLib that is clearly more recent?

GLib started only allowing including the top-level "glib.h" header years ago; I'm not entirely sure gnome-vfs was ever updated to do so, because it's been deprecated for 5 years, now.

in general, you want to try building a newer version of gnome-vfs — the latest is 2.24.4, released 3 years ago. if that does build, you'll have to modify gnome-vfs to always only include the top-level glib header. this means editing all source files that include things like "glist.h", "gmem.h", "gnode.h", etc. and replace them with:

#include <glib.h>

and then rebuild.

my actual suggestion, though, is to not use a deprecated library with no maintenance, and with known issues. if you have access to a recent version of GLib, you can use GIO — the library shipped with GLib that replaced gnome-vfs.

Upvotes: 2

Related Questions