(e-mail address removed) writes:
I am trying to complile a program in C using eclipse and I am
having this error:
undefined reference to `XTestFakeKeyEvent'
This is almost certainly a link error. In other words it describes
a missing definition -- some function (XTestFakeKeyEvent) is being
referred to but it is nowhere defined.
i used
#include <X11/keysym.h>
#include <X11/Xlib.h>
These things provide declarations of functions but only rarely do
they provide definitions. The definitions reside in libraries and
you must tell the linker (the part of the C compiler that puts your
program together from all it's different parts) where to find it.
On my system,using the command-line compiler gcc I just need to add
a link option like this:
$ gcc x.c -lXtst
Without that "-lXtst" (for the X11 test extension) I get the error
you report:
$ gcc x.c -lXext
/tmp/ccs8ziwK.o: In function `main':
x.c
.text+0xa): undefined reference to `XTestFakeKeyEvent'
collect2: error: ld returned 1 exit status
You'll have to find out how to do this in Eclipse some other way
since I've never used it.
But there is another very important matter. As others have said,
you probably need to
#include <X11/extensions/XTest.h>
because that's where XTestFakeKeyEvent is declared. The fact that
you are not also getting the message
warning: implicit declaration of function `XTestFakeKeyEvent'
means that you have not got the warning level set high enough, or
that you are compiling in some rather permissive non-standard mode.
You should, in general, ask for all the help the compiler can give
you, so I
always work with as many warnings turned on as I can stand. For
example:
$ gcc -Wall x.c
x.c: In function ‘main’:
x.c:6:6: warning: implicit declaration of function
‘XTestFakeKeyEvent’ [-Wimplicit-function-declaration]
which is something I would want to know.
#include <iostream>
Your problem happens to be the same in C and in C++,