Member
Registered: Jun 2006
Distribution: Kubuntu Hardy
Posts: 94
Rep:
|
Compiling with Xlib seems broken in DSL
I want to be able to develop Xlib applications on DSL, so I installed the XFree86-devel package. When I try to compile sample source generated with Anjuta with the following command:
gcc xstim.c -L/usr/X11R6/lib -lX11
it compiles successfully, but the binary doesn't work. Here's the source of xstim.c:
/* Created by Anjuta version 1.2.4a */
/* This file will not be overwritten */
/*Program closes with a mouse click or keypress */
#include <stdlib.h>
#include <stdio.h>
#include <X11/Xlib.h>
int main (int argc, char *argv[])
{
Display *dpy;
Visual *visual;
int depth;
XSetWindowAttributes attributes;
Window win;
XFontStruct *fontinfo;
XColor color, dummy;
XGCValues gr_values;
GC gc;
XKeyEvent event;
dpy = XOpenDisplay(NULL);
visual = DefaultVisual(dpy, 0);
depth = DefaultDepth(dpy, 0);
attributes.background_pixel = XWhitePixel(dpy, 0);
/* create the application window */
win = XCreateWindow(dpy, XRootWindow(dpy, 0),
50, 50, 400, 400, 5, depth,
InputOutput, visual, CWBackPixel,
&attributes);
XSelectInput(dpy, win, ExposureMask | KeyPressMask |
ButtonPressMask | StructureNotifyMask);
fontinfo = XLoadQueryFont(dpy, "6x10");
XAllocNamedColor(dpy, DefaultColormap(dpy, 0),
"green", &color, &dummy);
gr_values.font = fontinfo->fid;
gr_values.foreground = color.pixel;
gc = XCreateGC(dpy, win, GCFont+GCForeground, &gr_values);
XMapWindow(dpy, win);
/* run till key press */
while(1){
XNextEvent(dpy, &event);
switch(event.type) {
case Expose:
XDrawLine(dpy, win, gc, 0, 0, 100, 100);
XDrawRectangle(dpy, win, gc, 140, 140, 50, 50);
XDrawString(dpy, win, gc, 100, 100, "hello X world", 13);
break;
case ButtonPress:
case KeyPress:
XUnloadFont(dpy, fontinfo->fid);
XFreeGC(dpy, gc);
XCloseDisplay(dpy);
exit(0);
break;
case ConfigureNotify:
/* reconfigure size of window here */
break;
default:
break;
}
}
return(0);
}
It runs fine until it gets to case Expose:, where it has a segmentation fault. case KeyPress: also does it.
|