Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot call XInitThreads

Tags:

c++

sfml

xlib

I have written an SFML C++ game, and tried to start using threads, but after a while everything crashes. After searching I found out the fix seems to be to call XInitThreads(); but this does not work somehow.

simplified code:

    #include <X11/Xlib.h>   

    int main() {        
    XInitThreads();
    //other stuff
    return 1337;
    }

The error message I get when i try to compile is "undefined reference to symbol 'XInitThreads'. Could it be that the header file is working but there is no file where that method is implemented?

like image 574
user3554800 Avatar asked May 10 '14 19:05

user3554800


1 Answers

"undefined reference to symbol" is a linker error, not a compiler error. If you get this message, the compiler has already finished compiled the file into an object file, but is unable to find the shared library which contains the function to link the object file into an executable.

If you're using gcc, it generally means you have to add some -l flags, like so:

$ gcc prog.c -lX11

note that the order of -lX11 in the compiler argument matters, you would get an error if you do this:

$ gcc -lX11 prog.c
/tmp/ccBCxiFT.o: In function `main':
:(.text+0x5): undefined reference to `XInitThreads'
collect2: error: ld returned 1 exit status
like image 176
Lie Ryan Avatar answered Oct 21 '22 10:10

Lie Ryan