0

I may not be the first to ask about this; but I didn't find a solution yet. So maybe I'm not looking well.

I have compiled a small piece of code of 3 lines just to simulate a pressed key using xdo, with literally only one function call.

#include <cstdio>
#include <cstdlib>
#include <xdo.h>
#include <unistd.h>

int main() {
    xdo_t * x = xdo_new(":0.0");

    while(1) {
        xdo_send_keysequence_window_down(x, CURRENTWINDOW, "KP_Space", 1);
    }

    return 0; 
}

the cmake is looking like that:

cmake_minimum_required(VERSION 3.21)
project(remoteControl)
set(CMAKE_CXX_STANDARD 14)
include_directories(SYSTEM /usr/local/include)
link_libraries(/usr/local/lib/libxdo.so)
add_executable(remoteControl main.cpp)

I've tried with and without Cpp standard set. The execution give me:

[1]    55405 segmentation fault (core dumped)  ./remoteControl

So first I've looked for missing link

$> ldd ./remoteControl
    ...
   libxdo.so.3 => /usr/local/lib/libxdo.so.3 (0x00007fa110464000)
    ...
$> nm -u ./remoteControl
   ...
   U xdo_new
   U xdo_send_keysequence_window_down

So here we see that the xdo lib is well linked, bu there are missing symbols it, so I looked for these symbols over the libxdo.so file linked to the binary

$> nm -CgD /usr/local/lib/libxdo.so.3 | grep send
   ...
   0000000000006390 T xdo_send_keysequence_window_down
   ...

So, the symbol is defined in the linked lib, but undefined in the output file. I'm not competent enough to understand what could be the problem, so if anyone can healp it would be great, thanks !

EDIT: the problem had nothing to do with linker... like @Some programer dude said in the comments, xdo_new returns a null pointer on failure.

  • 2
    This is expected. The `.so` file will be linked dynamically when the program is run. Why do you assume that the error is due to a linking issue? – user17732522 Mar 06 '22 at 00:11
  • 1
    The crash is totally unrelated to both build- and run-time linking. If you have problems during linking (at build- or load-time) you would be getting more explicit errors, not segmentation faults (which are what happens when using invalid memory). – Some programmer dude Mar 06 '22 at 00:13
  • And have you checked what `xdo_new` *returns*? It doesn't return a null pointer? – Some programmer dude Mar 06 '22 at 00:13
  • Ok, I don't know why I automatically thought it was a linker error, @Someprogrammerdude you're right the problem was there, i didn't check if `xdo_new` was failing, and it was... Thank you ! – Julianit0w Mar 06 '22 at 00:18
  • Try this: https://stackoverflow.com/questions/67894/why-do-we-need-extern-c-include-foo-h-in-c – fukanchik Mar 06 '22 at 00:27

0 Answers0