【问题标题】:Linker error: undefined reference to symbol 'pthread_rwlock_trywrlock@@GLIBC_2.2.5'链接器错误:未定义对符号“pthread_rwlock_trywrlock@@GLIBC_2.2.5”的引用
【发布时间】:2013-04-21 20:59:44
【问题描述】:

我一直在使用 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

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

【问题讨论】:

  • 您的编译器/链接器命令行是否包含-pthread

标签: c++ qt gcc4.7


【解决方案1】:

我在尝试在 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

通过将LDFLAGS=-lpthread 直接传递给 lang/python37 或添加到/etc/make.conf 来解决。 如果使用 portmaster 安装/更新,请使用 -m 传递参数,例如portmaster -a -m 'LDFLAGS=-lpthread'

【讨论】:

    【解决方案2】:

    在我的小型笔记本电脑 Linux 中(我有各种各样的库), 我只需要添加

    LDFLAGS=-lpthread
    

    在配置命令参数的末尾。

    在那之后,make 完美地完成了它的工作(使用现有的库)。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        您想使用-pthread 进行编译,它不仅仅与 libpthread 链接:

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

        【讨论】:

          【解决方案5】:

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

          另请参阅:Adding external library into Qt Creator projecthttp://www.qtcentre.org/threads/39144-How-to-add-a-lib-to-a-qt-project

          顺便说一句,把你的 Makefile 贴出来,这样别人就可以指出确切的行了。

          【讨论】:

            猜你喜欢
            • 2018-06-11
            • 2016-03-12
            • 2014-10-26
            • 1970-01-01
            • 1970-01-01
            • 2013-04-07
            • 2023-03-30
            • 2020-11-19
            相关资源
            最近更新 更多