errors due to library functions being undefined,

A

alex.don253

I am trying to complile a program in C using eclipse and I am having this error:

undefined reference to `XTestFakeKeyEvent'

i used
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <iostream>

Could help me to solve that issue?
thanks
 
B

Ben Bacarisse

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++, but in general, C++
questions belong in comp.lang.c++.
 
J

Joachim Schmitz

Ben said:
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++,

In C++ (as well as in C99 and later) it shouldn't even compile in absence
of a declaration.
Not sure then how ther OP could have gotten a linker error?

Bye, Jojo
 
B

Ben Bacarisse

Joachim Schmitz said:
Ben said:
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++,

In C++ (as well as in C99 and later) it shouldn't even compile in
absence of a declaration.

There's no requirement that it shouldn't compile in C99; what's required
is that a diagnostic be issued. After that, the implementation can do
what it likes, and trying to link the problem seems to be a common
behaviour. I think the same is true of C++.
Not sure then how ther OP could have gotten a linker error?

The real question is why the OP did not get the required diagnostic
about the missing declaration, and that is covered by my remark to the
op: "you have not got the warning level set high enough, or that you are
compiling in some rather permissive non-standard mode". For example,
gcc will give you the error if you ask for C99 mode (-std=c99 -pedantic)
or if you turn on enough warnings (-Wimplicit-function-declaration as a
minimum, but -Wall would be better).
 
J

Joachim Schmitz

Ben said:
Joachim Schmitz said:
Ben said:
(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++,

In C++ (as well as in C99 and later) it shouldn't even compile in
absence of a declaration.

There's no requirement that it shouldn't compile in C99; what's
required is that a diagnostic be issued.

Ah, yes, I seem to often confuse those 2 things
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top