How to resolve error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’?
How to resolve error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’?
关于 incomplete type
错误的问题已经经常在这里被问到,但是那里提供的所有解决方案对我的情况都没有帮助。添加前向声明没有意义,因为 GdkSurface
已经在 Gdk headers 中被前向声明。包括适当的 headers 已经完成。在产生错误的代码部分之后 + includes.
#include <gdkmm/display.h>
#include <gdkmm/surface.h>
extern "C" {
#include <gdk/x11/gdkx.h>
#include <gdk/gdk.h>
}
extern "C" {
void surface_move(Gdk::Surface* psurface, int x, int y) {
#ifdef GDK_WINDOWING_X11
GdkSurface* surface = psurface->gobj();
GdkSurface *impl = GDK_X11_SURFACE(surface);
XMoveWindow(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
#endif
}
}
以下是完整的错误:
src/utils.cpp: In function ‘void Gdk::surface_move(Gdk::Surface*, int, int)’:
src/utils.cpp:9:83: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
src/utils.cpp:9:108: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
rface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
我用 JHbuild 构建了 Gdk、Gtk、Gdkmm 和 Gtkmm。
似乎这种类型在设计上是 GDK 私有的(只提供了前向声明)。来自 GDK4 documentation:
The GdkSurface
struct
contains only private fields and should not
be accessed directly.
参见 here 以了解定义它的 header(未分发)。这就是你得到这些错误的原因,你所拥有的只是一个前向声明来传递指针和引用。禁止对数据成员的所有访问。
要解决这个问题,您必须使用在表面(即 public)上工作的函数,例如 gdk_surface_get_scale_factor
或类似的东西,而不是尝试直接访问数据成员。
关于 incomplete type
错误的问题已经经常在这里被问到,但是那里提供的所有解决方案对我的情况都没有帮助。添加前向声明没有意义,因为 GdkSurface
已经在 Gdk headers 中被前向声明。包括适当的 headers 已经完成。在产生错误的代码部分之后 + includes.
#include <gdkmm/display.h>
#include <gdkmm/surface.h>
extern "C" {
#include <gdk/x11/gdkx.h>
#include <gdk/gdk.h>
}
extern "C" {
void surface_move(Gdk::Surface* psurface, int x, int y) {
#ifdef GDK_WINDOWING_X11
GdkSurface* surface = psurface->gobj();
GdkSurface *impl = GDK_X11_SURFACE(surface);
XMoveWindow(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
#endif
}
}
以下是完整的错误:
src/utils.cpp: In function ‘void Gdk::surface_move(Gdk::Surface*, int, int)’:
src/utils.cpp:9:83: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
src/utils.cpp:9:108: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
rface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
我用 JHbuild 构建了 Gdk、Gtk、Gdkmm 和 Gtkmm。
似乎这种类型在设计上是 GDK 私有的(只提供了前向声明)。来自 GDK4 documentation:
The
GdkSurface
struct
contains only private fields and should not be accessed directly.
参见 here 以了解定义它的 header(未分发)。这就是你得到这些错误的原因,你所拥有的只是一个前向声明来传递指针和引用。禁止对数据成员的所有访问。
要解决这个问题,您必须使用在表面(即 public)上工作的函数,例如 gdk_surface_get_scale_factor
或类似的东西,而不是尝试直接访问数据成员。