C++ 编译器未找到 #include <thread> [英] C++ compiler not finding #include &lt;thread&gt;

查看:84
本文介绍了C++ 编译器未找到 #include <thread>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的源文件的顶部:

Here is the top of my source file:

#include <iostream>
#include <thread>
#include <fstream>

...

thread help(startHelp);

线程在handleRequestsFromServer函数内部,startHelp是一个void函数.

Where the thread is inside the function handleRequestsFromServer and startHelp is a void function.

在 Mac OS X 10.8.4 上使用 g++ 编译时,出现此错误:

When compiling this with g++ on Mac OS X 10.8.4, I get this error:

$ g++ diskutilityhelper.cpp -o run.out
diskutilityhelper.cpp:5:18: error: thread: No such file or directory
diskutilityhelper.cpp: In function ‘void handleRequestsFromServer()’:
diskutilityhelper.cpp:140: error: ‘thread’ was not declared in this scope
diskutilityhelper.cpp:140: error: expected `;' before ‘bomb’

我完全不明白这个错误.有人可以帮忙吗?

I don't understand this error at all. Could anyone please help?

推荐答案

您可能想要使用 Clang 而不是 GCC.

You probably want to use Clang instead of GCC.

clang++ -std=c++11 -stdlib=libc++ diskutilityhelper.cpp -o run.out

GCC 的所有选项都可以与 Clang 一起使用,有些被忽略了.上面指向 libc++ 的链接,它是带有 Clang 的 Mac OS X 的首选 C++ 标准库(并且比 libstdc++ 完整得多(即使考虑到最新的 GCC).

All the options for GCC can be used with Clang, some are ignored. The above links to libc++, which is the preferred C++ standard library for Mac OS X with Clang (and a lot more complete than libstdc++ (even when considering the newest GCC).

至于发生这种情况的原因:我的神奇算命球告诉我你调用的 g++ 是一个古老的 GCC 4.2.1 Apple 东西,带有 GCC 的 libstdc++,它几乎没有 C++11 支持.Apple 改用 Clang,现在更受青睐.

As for the reason why this happens: my magic fortune telling ball tells me the g++ you are calling is an ancient GCC 4.2.1 Apple thingie, with that GCC's libstdc++, which has little to no C++11 support. Apple switched to Clang and it is now much preferred.

这篇关于C++ 编译器未找到 #include <thread>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆