“使用XCB库进行基本图形编程”中的代码中的“未声明”

s0s

这是导致问题的代码:

#include <string.h>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>

int main ()
{
  xcb_connection_t *c;
  xcb_screen_t     *screen;
  xcb_window_t      win;
  char             *title = "Hello World !";
  char             *title_icon = "Hello World ! (iconified)";



  /* Open the connection to the X server */
  c = xcb_connect (NULL, NULL);

  /* Get the first screen */
  screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;

  /* Ask for our window's Id */
  win = xcb_generate_id (c);

  /* Create the window */
  xcb_create_window (c,                             /* Connection          */
                     0,                             /* depth               */
                     win,                           /* window Id           */
                     screen->root,                  /* parent window       */
                     0, 0,                          /* x, y                */
                     250, 150,                      /* width, height       */
                     10,                            /* border_width        */
                     XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class               */
                     screen->root_visual,           /* visual              */
                     0, NULL);                      /* masks, not used     */

  /* Set the title of the window */
  xcb_change_property (c, XCB_PROP_MODE_REPLACE, win,
                       WM_NAME, STRING, 8,
                       strlen (title), title);

  /* fixed it by replacing WM_NAME with XCB_ATOM_WM_NAME
  and replacing STRING with XCB_ATOM_STRING */

  /* Set the title of the window icon */
  xcb_change_property (c, XCB_PROP_MODE_REPLACE, win,
                       WM_ICON_NAME, STRING, 8,
                       strlen(title_icon), title_icon);

  /* fixed this by replacing WM_ICON_NAME with XCB_ATOM_ICON_NAME
  and replacing STRING with XCB_ATOM_STRING */

  /* Map the window on the screen */
  xcb_map_window (c, win);

  xcb_flush (c);

  while (1) {}

  return 0;
}

gcc产生错误,因为未在任何地方定义WM_NAME和WM_ICON_NAME;XCB_ATOM_应该已经在前面。我通过在线阅读论坛帖子和阅读xproto.h找到了解决方案

但是,似乎没有在任何地方定义STRING。我搜索了string.h。仅在评论中找到了STRING的情况。我尝试将STRING更改为字符串,但仍无法编译。

$ gcc -Wall -o win-icon-name win-icon-name.c -lxcb
win-icon-name.c: In function ‘main’:
win-icon-name.c:40:42: error: ‘string’ undeclared (first use in this function)
                        XCB_ATOM_WM_NAME, string, 8,
                                          ^
win-icon-name.c:40:42: note: each undeclared identifier is reported only once for each function it appears in

我通过将“ XCB_ATOM_”放在“ STRING”之前解决了该问题,并且编译得很好。

s0s

正如Clifford所建议的,这是带有固定代码的单独文章。

#include <string.h>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>

int main ()
{
  xcb_connection_t *c;
  xcb_screen_t     *screen;
  xcb_window_t      win;
  char             *title = "Hello World !";
  char             *title_icon = "Hello World ! (iconified)";



  /* Open the connection to the X server */
  c = xcb_connect (NULL, NULL);

  /* Get the first screen */
  screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;

  /* Ask for our window's Id */
  win = xcb_generate_id (c);

  /* Create the window */
  xcb_create_window (c,                             /* Connection          */
                     0,                             /* depth               */
                     win,                           /* window Id           */
                     screen->root,                  /* parent window       */
                     0, 0,                          /* x, y                */
                     250, 150,                      /* width, height       */
                     10,                            /* border_width        */
                     XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class               */
                     screen->root_visual,           /* visual              */
                     0, NULL);                      /* masks, not used     */

  /* Set the title of the window */
  xcb_change_property (c, XCB_PROP_MODE_REPLACE, win,
                       XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8,
                       strlen (title), title);

  /* Set the title of the window icon */
  xcb_change_property (c, XCB_PROP_MODE_REPLACE, win,
                       XCB_ATOM_WM_ICON_NAME, XCB_ATOM_STRING, 8,
                       strlen(title_icon), title_icon);

  /* Map the window on the screen */
  xcb_map_window (c, win);

  xcb_flush (c);

  while (1) {}

  return 0;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ggplot2是否使用/继承R基本图形中的某些参数?

使用 for 循环值创建基本图形

使用基本图形的点图

使用 tensorflow 进行基本图像分类

如何在基本图形中复制 ggplot2::geom_raster?

在Swift中对我自己的ViewController进行单元测试时,使用未声明的类型'ViewController'吗?

是否可以在尚未声明的共享库中调用函数?

在VBA中未声明函数

在 Perl 中捕获未声明的文件句柄使用

解析中的“使用未声明的标识符'PFUser'”

错误:未声明“ asm”(此函数中的首次使用)

未声明CLONE_VM(此函数中的首次使用)

如何使用ESLint在React中捕获未声明的变量?

NSMultipleValuesMarker在Swift 3中使用未声明的类型

未声明错误“listaCliente”(在此函数中首次使用)

Xcode中的错误“使用未声明的类型”不会消失

在Swift 3中使用未声明的类型

在Swift 3中使用未声明的类型“ Decodable” /“ Codable”

错误:“数学”未声明在此函数中首次使用

ViewController中的Swift错误“使用未声明的类型”

如何修复Swift 5.1中的“使用未声明类型”错误?

错误:未声明边缘(在函数中首次使用)

使用Dojo的gfx库更改文本图形对象的文本

在基本的GUI编程中,哪里声明对象和方法?

如何使用 Pillow 模块将列表中的图像组粘贴到基本图像之上?

LibreOffice Calc-绘制基本图形

基本图形。在绘图中需要帮助

使用python中的unittest库进行代码测试

编译器错误:C代码中“在此范围内未声明'e'”