LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > DamnSmallLinux
User Name
Password
DamnSmallLinux This forum is for the discussion of DamnSmallLinux.

Notices

Reply
 
Search this Thread
Old 06-10-2006, 12:02 PM   #1
JoeyAdams
Member
 
Registered: Jun 2006
Distribution: Kubuntu Hardy
Posts: 94

Rep: Reputation: 15
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.
 
Old 06-12-2006, 04:09 PM   #2
JoeyAdams
Member
 
Registered: Jun 2006
Distribution: Kubuntu Hardy
Posts: 94

Original Poster
Rep: Reputation: 15
Oh, by the way, I can make a program with Xlib that runs fine on DSL if I compile it on Fedora Core 5 using Xorg.
 
Old 06-12-2006, 05:55 PM   #3
JoeyAdams
Member
 
Registered: Jun 2006
Distribution: Kubuntu Hardy
Posts: 94

Original Poster
Rep: Reputation: 15
I figured it out. The example was bugged. An XKeyEvent is not as large as an XEvent, and there are many types of events larger than XKeyEvent that the window can receive. When one of these events is received, whatever's after the XKeyEvent is hosed.

I guess the implementation of Xlib on Fedora Core 5 makes all event structures the same size.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Xlib: connection to ":0.0" refused by server Xlib: No protocol specified eyalkz Linux - Newbie 10 02-07-2014 12:53 AM
flags for compiling Xlib.h in gcc Maidros Programming 2 06-15-2005 05:00 AM
kde lib for compiling broken package qwertyuiop Debian 5 10-01-2004 06:31 PM
Xlib: connection to ":0.0" refused by server Xlib: No protocol specified eyalkz Programming 1 03-02-2004 08:22 AM
X seems to be broken after compiling alternate kernel BenjiF Linux - Software 3 08-23-2003 02:01 AM


All times are GMT -5. The time now is 11:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration