这是导致问题的代码:
#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”之前解决了该问题,并且编译得很好。
正如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] 删除。
我来说两句