无法调用 XInitThreads [英] Cannot call XInitThreads

查看:85
本文介绍了无法调用 XInitThreads的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 SFML C++ 游戏,并尝试开始使用线程,但一段时间后一切都崩溃了.搜索后我发现修复似乎是调用 XInitThreads();但这以某种方式不起作用.

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.

简化代码:

    #include <X11/Xlib.h>   

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

当我尝试编译时收到的错误消息是未定义对符号'XInitThreads'的引用.难道头文件正在工作,但没有实现该方法的文件?

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?

推荐答案

未定义的符号引用"是链接器错误,而不是编译器错误.如果您收到此消息,则编译器已将文件编译为目标文件,但无法找到包含将目标文件链接为可执行文件的函数的共享库.

"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.

如果您使用 gcc,通常意味着您必须添加一些 -l 标志,如下所示:

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

$ gcc prog.c -lX11

注意编译器参数中 -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

这篇关于无法调用 XInitThreads的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆