Xlib not found, Fedora Core 4
The g++ compiler doesn't seem to find Xlib.h on my machine. I know the file is in /usr/X11R6/include/X11. In /usr/include there is a link to the X11 folder. The compiler says this if I run:
Code:
# g++ -o test1.out test1.cpp
/tmp/ccYcKmMS.o(.text+0x11): In function `main':
test1.cpp: undefined reference to `XOpenDisplay'
/tmp/ccYcKmMS.o(.text+0xe0):test1.cpp: undefined reference to `XCreateSimpleWindow'
/tmp/ccYcKmMS.o(.text+0xf1):test1.cpp: undefined reference to `XMapWindow'
/tmp/ccYcKmMS.o(.text+0x108):test1.cpp: undefined reference to `XCreateGC'
/tmp/ccYcKmMS.o(.text+0x11f):test1.cpp: undefined reference to `XSetForeground'
/tmp/ccYcKmMS.o(.text+0x12f):test1.cpp: undefined reference to `XNextEvent'
/tmp/ccYcKmMS.o(.text+0x163):test1.cpp: undefined reference to `XDrawLine'
/tmp/ccYcKmMS.o(.text+0x16c):test1.cpp: undefined reference to `XFlush'
collect2: ld returned 1 exit status
I get the same errors if I run: g++ -I /usr/X11R6/include/ -o test1.out test1.cpp
Here are the contents of test1.cpp:
Code:
#include <X11/Xlib.h>
#include <assert.h>
#include <unistd.h>
#define NIL (0)
int main()
{
Display *dpy = XOpenDisplay(NIL);
assert(dpy);
int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200,
100, 0, blackColor, blackColor);
XMapWindow(dpy, w);
GC gc = XCreateGC(dpy, w, 0, NIL);
XSetForeground(dpy, gc, whiteColor);
while(1)
{
XEvent e;
XNextEvent(dpy, &e);
if(e.type == MapNotify)
break;
}
XDrawLine(dpy, w, gc, 10, 60, 180, 20);
XFlush(dpy);
sleep(10);
return 0;
}
There shouldn't be anything wrong with the source code since I copied it from a tutorial page.