链接器错误:对符号'pthread_rwlock_trywrlock @@ GLIBC_2.2.5'的未定义引用

seg*_*ult 6 c++ qt gcc4.7

我一直在开发CentOS,Qt 4.7和GCC 4.4

我刚刚安装了包含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
Run Code Online (Sandbox Code Playgroud)

我猜测Qt线程正在引用它.我该如何解决?

Ben*_*son 14

你想编译的-pthread不仅仅是链接libpthread:

使用pthreads库添加对多线程的支持.此选项为预处理器和链接器设置标志.


小智 5

阅读注释:尝试添加/lib64/libpthread.so.0到 Makefile 中(在命令-lpthread之后,或之后(或之后)),或者类似的东西,如果某处有这样的定义。gcc/lib64/libpthread.so.0ldgcc -sharedLIB += -lpthread

另请参阅:将外部库添加到 Qt Creator 项目http://www.qtcentre.org/threads/39144-How-to-add-a-lib-to-a-qt-project

顺便说一句,发布你的 Makefile,这样有人就能够指向确切的行。


cma*_*t85 5

您只需要添加CONFIG += thread到您的.pro文件中.