当前位置: 技术问答>linux和unix
紧急求助:为什么会出现这个错误?
来源: 互联网 发布时间:2016-11-08
本文导语: 首先是从自己的笔记本链接上 一个 server ,然后写上如下程序: #include // X11 library headers #include #include #define X_RESN 800 /* x resolution */ #define Y_RESN 800 /* y resolution */ #include int main (int argc, char **arg...
首先是从自己的笔记本链接上 一个 server ,然后写上如下程序:
然后输入如下命令:
gcc -I/usr/openwin/include Cprogram.c -o Cprogram -L/usr/openwin/lib -L/usr/X11R6/lib -lX11
然后输入 ./Cprogram
然后就出现了如下提示:drawon: cannot connect to X server Jinbo
我注意到程序里面的这一段:
但是不知道为什么会出现这个错误?drawon: cannot connect to X server Jinbo ?????
#include // X11 library headers
#include
#include
#define X_RESN 800 /* x resolution */
#define Y_RESN 800 /* y resolution */
#include
int main (int argc, char **argv ) {
/* --------------------------- X11 graphics setup ------------------------------ */
Window win; /* initialization for a window */
unsigned int width, height, /* window size */
win_x,win_y, /* window position */
border_width, /* border width in pixels */
display_width, display_height, /* size of screen */
screen; /* which screen */
char *window_name = "My graphics program", *display_name = "Jinbo";
GC gc;
unsigned long valuemask = 0;
XGCValues values;
Display *display;
XSizeHints size_hints;
Pixmap bitmap;
XPoint points[800];
FILE *fp, *fopen ();
char str[100];
XSetWindowAttributes attr[1];
if ( (display = XOpenDisplay (display_name)) == NULL ) { /* connect to Xserver */
fprintf (stderr, "drawon: cannot connect to X server %sn",XDisplayName (display_name) );
exit (-1);
}
screen = DefaultScreen (display); /* get screen size */
display_width = DisplayWidth (display, screen);
display_height = DisplayHeight (display, screen);
width = X_RESN; /* set window size */
height = Y_RESN;
win_x = 0; win_y = 0; /* set window position */
border_width = 4; /* create opaque window */
win = XCreateSimpleWindow (display, RootWindow (display, screen),
win_x, win_y, width, height, border_width,
BlackPixel (display, screen), WhitePixel (display, screen));
size_hints.flags = USPosition|USSize;
size_hints.x = win_x;
size_hints.y = win_y;
size_hints.width = width;
size_hints.height = height;
size_hints.min_width = 300;
size_hints.min_height = 300;
XSetNormalHints (display, win, &size_hints);
XStoreName(display, win, window_name);
gc = XCreateGC (display, win, valuemask, &values); /* create graphics context */
XSetBackground (display, gc, WhitePixel (display, screen));
XSetForeground (display, gc, BlackPixel (display, screen));
XSetLineAttributes (display, gc, 1, LineSolid, CapRound, JoinRound);
attr[0].backing_store = Always;
attr[0].backing_planes = 1;
attr[0].backing_pixel = BlackPixel(display, screen);
XChangeWindowAttributes(display, win, CWBackingStore | CWBackingPlanes | CWBackingPixel, attr);
XMapWindow (display, win);
XSync(display, 0);
}
然后输入如下命令:
gcc -I/usr/openwin/include Cprogram.c -o Cprogram -L/usr/openwin/lib -L/usr/X11R6/lib -lX11
然后输入 ./Cprogram
然后就出现了如下提示:drawon: cannot connect to X server Jinbo
我注意到程序里面的这一段:
if ( (display = XOpenDisplay (display_name)) == NULL ) { /* connect to Xserver */
fprintf (stderr, "drawon: cannot connect to X server %sn",XDisplayName (display_name) );
exit (-1);
}
但是不知道为什么会出现这个错误?drawon: cannot connect to X server Jinbo ?????
|
会不会是和xhost命令有关?