开罗到开罗-xlib : cairo_xlib_surface_create problems (C)

标签 c linux cairo xlib

我正在尝试从 Cairo 图像表面切换到 xlib 表面。我的代码在图像表面上运行良好,但我认为我没有正确初始化 xlib 表面。它可以编译,但会抛出警告并且不再显示任何内容。

这是我当前用于初始化表面的代码:

    int width, height;
    gdk_threads_enter();
    gdk_drawable_get_size(pixmap, &width, &height);
    gdk_threads_leave();

    /*** Create surface to draw on ***/
    cairo_surface_t *cst = cairo_xlib_surface_create(gdk_x11_drawable_get_xdisplay(pixmap),
                                        gdk_x11_drawable_get_xid(pixmap),
                                        gdk_x11_visual_get_xvisual(gvis), 
                                        width, height);

编译时出现如下警告:

In function 'do_draw':
evis.c:112:11: warning: passing argument 1 of 'cairo_xlib_surface_create' makes pointer from integer without a cast [enabled by default]
           width, height);
           ^
In file included from evis.c:6:0:
/usr/include/cairo/cairo-xlib.h:49:1: note: expected 'struct Display *' but argument is of type 'int'
 cairo_xlib_surface_create (Display     *dpy,
 ^
evis.c:112:11: warning: passing argument 3 of 'cairo_xlib_surface_create' makes pointer from integer without a cast [enabled by default]
           width, height);
           ^
In file included from evis.c:6:0:
/usr/include/cairo/cairo-xlib.h:49:1: note: expected 'struct Visual *' but argument is of type 'int'
 cairo_xlib_surface_create (Display     *dpy,
 ^

我很确定这些警告会破坏代码,但我不确定如何修复它们。我尝试将第一个参数和第三个参数分别转换为 (Display *)(Visual *) 但这也不起作用。开始发出其他警告。

*编辑 1 * 试图理解这一点,但到目前为止我对指针的理解仅限于不存在。 gdk_drawable_get_xdisplay() 返回一个 Display* 但我的函数正在寻找一个指向 struct Display * 的指针。 2 之间有什么区别,我如何从 Display*Display *

最佳答案

编译器认为函数返回 int 的“通常”原因(这是这里发生的情况,因为它提示这两个函数的结果)是它找不到函数的原型(prototype),这意味着你错过了#include。 (虽然我希望在那种情况下找到其他警告?)

关于开罗到开罗-xlib : cairo_xlib_surface_create problems (C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20763560/

相关文章:

c++ - 使用某些静态库时在开罗出现段错误

python - Python ctypes 和 librsvg 出错

c - 如何使用 mmap 映射空文件

c - 在 C 中使用系统调用 write() 打印彩色字符串

c - 十进制到十六进制单位转换

c++ - C++中 "type-safety"的确切含义是什么?

linux - 在 Linux 中执行文件操作时如何排除文件夹,即 cp、mv、rm 和 chown 等

c - 什么是正确的 fcntl 标志?

linux - 使用 SED 更新配置文件中特定字符串后的 IP 值

c++ - 简单的C++图形库