2017-01-09 13 views
-1

여기에 문제가 발생하는 코드였다 WM_NAME 및 WM_ICON_NAME 어디서나 정의되지 않았기 때문에는 "XCB 라이브러리와 기본 그래픽 프로그래밍"에서 코드에서 "신고되지 않은 '문자열'"

#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 오류가 생성 된 ; 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 

"STRING"앞에 "XCB_ATOM_"을 넣어서 문제를 해결했으며 잘 컴파일되었습니다.

+0

코드는 여기에 직접 게시해야합니다. 튜토리얼이 변경되어 귀하의 질문이 유효하지 않을 수 있습니다. 코드에 대한 SO의 질문은 유효합니다. 더 나은 튜토리얼을 요구하는 것은 아닙니다. – Clifford

+0

자습서 색인 링크 13.2는 실제로 12.2 (어떤 경우에도 참조하는 코드 인 것처럼 보입니다)로 이동합니다. 오프 사이트 리소스를 참조하는 대신 코드를 게시해야하는 또 다른 이유입니다. – Clifford

+0

@sOs : 어쩌면 당신의 대답은 어쩌면 결국 대답 일지 모르지만 문제를 해결했다는 것이 전혀 분명하지 않습니다. 적어도 자신의 대답을 명확하게하고 심지어 받아 들여야합니다. 그러나 여러분의 문제는 아마'STRING' 대신'string'을 사용했을 것이라는 것을 알게되었습니다. 당신은 분명히 복사 & 붙여 넣기를 전혀하지 않았습니다! – Clifford

답변

1

클 리 포드 (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; 
}