我正在构建 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
这就是我遇到的问题,但没有解决方案