简体   繁体   中英

GTK 3.0 gives compiler error “Only <gdk/gdkh> can be included directly”

Working on a GTK++ project. The thing compiled successfully when using Ubuntu's libgtk2.0-dev library. After removing that library and installing libgtk3.0-dev library, I get the following error message at compile time:

In file included from file_operations.c:4:0:
/usr/include/gtk-3.0/gdk/gdkevents.h:26:2 #error: Only <gdk/gdkh> can be included directly.

Here is the compile command:

gcc -Wall -o gexplorer2 main.c file_operations.c -I. -I/usr/include/gnome-vfs-2.0 -D _FILE_OFFSET_BITS=64 `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0` `pkg-config --cflags gio-2.0`

file_operations.c has the following includes:

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkevents.h>

In gdkevents.h, the following lines generate the compiler error

#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
#error "Only <gdk/gdkh> can be included directly."
#endif

(These lines were not in GTK 2.0's include files.)

Guesses or knowledge on what is causing this error, and how to resolve?

The idea here seems to be that the GDK authors want to discourage you from including specific GDK headers directly (presumably because those headers have subtle dependencies that are not spelled out with explicit includes).

So just do what they say, remove your <gdk/x> includes and include <gdk/gdkh> instead. Presumably, that should include the APIs you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM