Hello
Check this code
When I run this program I get the error: ZeroLink: unknown symbol '_XOpenDisplay'
I think that there is a library missing. Any Unix developers out there who can help me?
Check this code
Code:
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
Display * mydisplay;
Window mywindow;
GC mygc;
XEvent myevent;
KeySym mykey;
XSizeHints myhint;
int myscreen;
unsigned long myforeground,
mybackground;
XFontStruct * font_struct;
/* declarations */
char window_title[] = {"Hello World"};
main (argc, argv)
int argc;
char **argv;
{
int i;
char text[10];
int done;
XColor greencolor;
XColor rgb;
mydisplay = XOpenDisplay ("");
myscreen = DefaultScreen (mydisplay);
/* default pixel values */
mybackground = WhitePixel (mydisplay, myscreen);
myforeground = BlackPixel (mydisplay, myscreen);
/* default program-specified window position and size */
myhint.x = 10;
myhint.y = 10;
myhint.width = 250;
myhint.height = 150;
myhint.flags = PPosition | PSize;
/* window creation */
mywindow = XCreateSimpleWindow (mydisplay,
DefaultRootWindow (mydisplay),
myhint.x, myhint.y, myhint.width,
myhint.height,
5, myforeground, mybackground);
XSetStandardProperties (mydisplay, mywindow, window_title, window_title,
None, argv, argc, &myhint);
/* GC creation and initialization */
mygc = XCreateGC (mydisplay, mywindow, 0, 0);
XSetBackground (mydisplay, mygc, mybackground);
XSetForeground (mydisplay, mygc, myforeground);
XAllocNamedColor(mydisplay, DefaultColormap(mydisplay, myscreen),
"MediumForestGreen", &greencolor, &rgb);
/* font initialization */
font_struct = XLoadQueryFont (mydisplay, "*courier-bold-r-normal--14*");
XSetFont (mydisplay, mygc, font_struct -> fid);
/* input event selection */
XSelectInput (mydisplay, mywindow,
ButtonPressMask | KeyPressMask | ExposureMask);
/* window mapping */
XMapRaised (mydisplay, mywindow);
XFlush (mydisplay);
/* main event-reading loop */
done = 0;
while (done == 0) {
/* read the next event */
XNextEvent (mydisplay, &myevent);
switch (myevent.type) {
/* repaint window on expose events */
case Expose:
XSetForeground(mydisplay, mygc, myforeground);
XDrawString (mydisplay, mywindow, mygc, 10, 60, "Hello, World", 12);
XDrawRectangle(mydisplay, mywindow, mygc, 5, 47, 150, 15);
if (myevent.xexpose.count == 0)
XFlush (mydisplay);
break;
/* process mouse-button presses */
case ButtonPress:
done = 1;
break;
/* process keyboard input */
case KeyPress:
i = XLookupString (&myevent, text, 10, &mykey, 0);
if (i == 1 && text[0] == "q")
done = 1;
break;
default:
break;
} /* switch (myevent.type) */
} /* while (done == 0) */
/* termination */
XFreeGC (mydisplay, mygc);
XDestroyWindow (mydisplay, mywindow);
XCloseDisplay (mydisplay);
exit(0);
}
I think that there is a library missing. Any Unix developers out there who can help me?