【问题标题】:g++ libstdc++-v3 ‘thread’ is not a member of ‘std’g++ libstdc++-v3‘thread’不是‘std’的成员
【发布时间】:2019-09-29 22:29:30
【问题描述】:

我正在构建 gcc 9.10,它适用于 c 线程,但我用 g++ 和 libstdc++-v3 做错了,我只是不知道是什么。

我编译 gcc/g++、glibc 和 libstdc++-v3 我看到文件在 include/c++/9.1.0/threads 当我去编译一个简单的测试程序时,我得到了

error: ‘thread’ is not a member of ‘std’

C pthread 测试程序编译

#include <pthread.h>
int main(){
    tpthread_t t;
}

C 测试程序编译

#include <threads.h>
int main(){
    thrd_t t;
}

Cxx 测试程序无法编译

#include <thread>
int main(){
    std::thread t;
}

得到错误

error: ‘thread’ is not a member of ‘std’

查看头文件 include/c++/9.1.0/threads

#if defined(_GLIBCXX_HAS_GTHREADS)

如果没有定义,它看起来会跳过所有内容 我如何检查是否是这种情况,然后为什么?

我做了这个小测试,它编译后告诉我 _GLIBCXX_HAS_GTHREADS 没有定义

int main(){
    #if defined(_GLIBCXX_HAS_GTHREADS)
    123 here error
    #endif
}

在编译 libstdc++-v3 时我使用

../libstdc++-v3/configure -v --enable-libstdcxx-threads=yes

尽管我认为应该在 linux x64 系统上默认启用线程

另一个问题对我的情况没有帮助,这是很久以前的情况,gcc 已经改变。一条评论似乎涉及我的问题,但没有深入

If you look in the thread header, it appears that the class only exists #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1). I'm not sure though, what you'd have to do to have those defined

这就是我遇到的问题,但没有解决方案

【问题讨论】:

  • 我相信这可能显示了相同的错误,但原因不同。 Gcc 现在默认有线程,我没有使用 -ansi,也没有交叉编译。我可以使用 ubuntu 7.4 版并编译 cxx 测试,所以我认为我的配置有问题
  • @jeff8j 您能否提及您正在运行的编译命令?
  • 添加 --enable-threads=yes 是我所缺少的 ../libstdc++-v3/configure -v --enable-threads=yes --disable-multilib make -j 8 make install测试现在可以使用 g++ test.cxx 进行编译

标签: c++11 gcc


【解决方案1】:

答案是使用 --enable-threads=yes 进行配置,我不知道为什么这很难找到,为什么这不是默认设置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    相关资源
    最近更新 更多