1

i'm working in a little c++ application, i'm trying to use xdotool (libxdo: https://github.com/jordansissel/xdotool ).

i builded xdotool using the "make" command, and put the libxdo.so and libxdo.so.3 into /usr/lib. and xdo.h into /usr/local/include.

im trying to compile my application using:

g++ -I /usr/local/include/ -L /usr/lib/ LinuxTest.cpp -lXtst -lX11 -lxdo

but im getting this error:

undefined reference to `xdo_new(char const*)'
undefined reference to `xdo_move_mouse_relative(xdo const*, int, int)'

this is my source code:

#include <iostream>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/X.h>
#include <unistd.h>
#include <X11/extensions/XTest.h>
#include <xdo.h>

using namespace std;

#define KEYCODE XK_Tab
int mapa[2048];
void hook();

xdo_t* xdoMain;

int main() {
    for (int i=0;i<2048;i++){
       mapa[i]=0;
    }
    xdoMain = xdo_new(NULL);
    xdo_move_mouse_relative(xdoMain,200,200);
    hook(); //do some things using X11
    return 0;
}
1
  • Have you run ldconfig after you put the lib into /usr/lib? Commented May 17, 2015 at 23:11

1 Answer 1

2

I am guessing this is because xdo is a C library.
You are linking and building a C++ application.

Thus your compiler is thinking that xdo_new() is a C++ name mangled function. But in reality it has been linked into libxdo. as a C name mangled function.

I would try this:

extern "C" {
#include <xdo.h>
}

You are basically telling the compiler to treat all the names in xdo as C function declarations. As long as there are no classes this should work (if there are classes then my assumption is incorrect to start with).

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much, I didn't know that XDO is a C library, besides that I'm not often c ++ programmer
@moscoquera: If a library has new/free functions then it is probably is a C library, as C++ uses a technique called RAII that makes this redundant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.