errors due to library functions being undefined,

Discussion in 'C Programming' started by alex.don253@gmail.com, Dec 10, 2012.

  1. Guest

    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
     
    , Dec 10, 2012
    #1
    1. Advertising

  2. Noob Guest

    Re: errors due to library functions being undefined

    alex.don253 wrote:

    > undefined reference to `XTestFakeKeyEvent'


    FAQ 13.25
    http://c-faq.com/lib/extlibs.html
    -lXtst seems like a good candidate.

    > #include <X11/keysym.h>
    > #include <X11/Xlib.h>


    (Please note that this discussion is off-topic)
    According to the man page, you might need to
    #include <X11/extensions/XTest.h>
    http://linux.die.net/man/3/xtestfakekeyevent

    > #include <iostream>


    If you want to discuss specific C++ features, you can use the
    comp.lang.c++ news group.

    Regards.
     
    Noob, Dec 10, 2012
    #2
    1. Advertising

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

    > Could help me to solve that issue?
    > thanks


    --
    Ben.
     
    Ben Bacarisse, Dec 10, 2012
    #3
  4. Ben Bacarisse wrote:
    > 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.
    Not sure then how ther OP could have gotten a linker error?

    Bye, Jojo
     
    Joachim Schmitz, Dec 10, 2012
    #4
  5. "Joachim Schmitz" <> writes:

    > Ben Bacarisse wrote:
    >> 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. 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).

    --
    Ben.
     
    Ben Bacarisse, Dec 10, 2012
    #5
  6. Ben Bacarisse wrote:
    > "Joachim Schmitz" <> writes:
    >
    >> Ben Bacarisse wrote:
    >>> 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
     
    Joachim Schmitz, Dec 10, 2012
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    966
    Mark Goldin
    Jan 17, 2004
  2. Shuaib
    Replies:
    1
    Views:
    1,026
    Shuaib
    Aug 19, 2006
  3. Replies:
    5
    Views:
    710
    Ron Natalie
    Nov 20, 2006
  4. Fresh
    Replies:
    2
    Views:
    639
    Bo Persson
    Apr 22, 2008
  5. smccreadie
    Replies:
    0
    Views:
    228
    smccreadie
    Oct 27, 2006
Loading...

Share This Page