C++ 链接器错误:未定义对符号“pthread_rwlock_trywrlock@@GLIBC_2.2.5”的引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16257564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linker error: undefined reference to symbol 'pthread_rwlock_trywrlock@@GLIBC_2.2.5'
提问by segfault
I've been developing with CentOS, Qt 4.7, and GCC 4.4
我一直在使用 CentOS、Qt 4.7 和 GCC 4.4 进行开发
I've just installed Red Hat Developer Toolset 1.1 which includes GCC 4.7.2, and at the end of make
, I get an error
我刚刚安装了包含 GCC 4.7.2 的 Red Hat Developer Toolset 1.1,并且在最后make
,我收到一个错误
/usr/bin/ld: ../../bin/Solo: undefined reference to symbol 'pthread_rwlock_trywrlock@@GLIBC_2.2.5'
/usr/bin/ld: note: 'pthread_rwlock_trywrlock@@GLIBC_2.2.5' is defined in DSO /lib64/libpthread.so.0 so try adding it to the linker command line
/lib64/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
I'm guessing that Qt threads is referencing to that. How can I fix it?
我猜 Qt 线程正在引用它。我该如何解决?
回答by Ben Hymanson
You want to compile with -pthread
which does more than just link with libpthread:
你想用-pthread
which编译不仅仅是与 libpthread 链接:
Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker.
使用 pthreads 库添加对多线程的支持。此选项为预处理器和链接器设置标志。
回答by cmannett85
You just need to add CONFIG += thread
to your .pro
file.
您只需要添加CONFIG += thread
到您的.pro
文件中。
回答by lmns
Read the note: try to add /lib64/libpthread.so.0
into Makefile (-lpthread
after gcc
command, or /lib64/libpthread.so.0
after ld
(or after gcc -shared
)), or something like LIB += -lpthread
if there's such definition somewhere.
阅读注释:尝试添加/lib64/libpthread.so.0
到 Makefile (-lpthread
在gcc
命令之后,或/lib64/libpthread.so.0
之后ld
(或之后gcc -shared
)),或者类似的东西,LIB += -lpthread
如果某处有这样的定义。
See also: Adding external library into Qt Creator projectand http://www.qtcentre.org/threads/39144-How-to-add-a-lib-to-a-qt-project
另请参阅:将外部库添加到 Qt Creator 项目和http://www.qtcentre.org/threads/39144-How-to-add-a-lib-to-a-qt-project
Btw, post your Makefile, so somebody will be able to point to exact line.
顺便说一句,发布您的 Makefile,以便有人能够指出确切的行。
回答by George Moraitis
In my little laptop Linux (where I have a mixed bag of libraries), I just had to add
在我的小型笔记本电脑 Linux(我有一大堆库)中,我只需要添加
LDFLAGS=-lpthread
AT THE END of the configure command arguments.
在配置命令参数的末尾。
After that, make did its job perfectly (With the existing libraries).
在那之后, make 完美地完成了它的工作(使用现有的库)。
回答by denrad
I received similar 'Linker error: undefined reference to symbol' errors attempting to compile and install Python-3.7.2 on FreeBSD 12.
我在尝试在 FreeBSD 12 上编译和安装 Python-3.7.2 时收到类似的“链接器错误:未定义对符号的引用”错误。
/usr/bin/ld: error: undefined symbol: _Py_GetGlobalVariablesAsDict
/usr/bin/ld: error: undefined symbol: _PyCoreConfig_AsDict
/usr/bin/ld: error: undefined symbol: _PyMainInterpreterConfig_AsDict
Resolved by passing LDFLAGS=-lpthread
directly to make of lang/python37 or by adding to /etc/make.conf
.
If using portmaster to install/update use -m
to pass the arguement to make e.g.portmaster -a -m 'LDFLAGS=-lpthread'
通过LDFLAGS=-lpthread
直接传递给 make of lang/python37 或通过添加到/etc/make.conf
. 如果使用 portmaster 来安装/更新使用-m
传递论证来使例如portmaster -a -m 'LDFLAGS=-lpthread'