includeheader-filesxlib

XTestFakeButtonEvent not defined, how to find the right includes?


I'm writing some C code using the X11 API, and want to use the function XTestFakeButtonEvent.

According to the docs I'd need to include <X11/extensions/XTest.h>.

I had to install libXtst-devel to be able to include it.

However, when I compile I still get this error:

/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /tmp/cc4pbNhk.o: in function `main':
mouse-chording.c:(.text+0x7bf): undefined reference to `XTestFakeButtonEvent'
collect2: error: ld returned 1 exit status

Is libXtst-devel not the right package?

I compile with the following command:

gcc mouse-chording.c -o mouse-chording.exe -lX11 

#include "X11/Xlib.h" was not enough, appearently, I also needed to add -lX11 to the compilation command.

Do I have to do something similar for XTest?

Using OpenSUSE Tumbleweed with XFCE.


Solution

  • Checked what xdotool does, since it is using the same library.

    The Makefile has -lXtst so I added this to the make command and it works.

    The inconsistency in naming is kind of confusing though; XTest, libXtst, and lXtst