jam*_*ick 1 c++ multithreading g++
这是我的源文件的顶部:
#include <iostream>
#include <thread>
#include <fstream>
Run Code Online (Sandbox Code Playgroud)
...
thread help(startHelp);
Run Code Online (Sandbox Code Playgroud)
其中线程在函数handleRequestsFromServer和startHelp中是一个void函数.
g++在Mac OS X 10.8.4上编译时,我收到此错误:
$ 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’
Run Code Online (Sandbox Code Playgroud)
我根本不明白这个错误.有人可以帮忙吗?
您可能想要使用Clang而不是GCC.
clang++ -std=c++11 -stdlib=libc++ diskutilityhelper.cpp -o run.out
Run Code Online (Sandbox Code Playgroud)
GCC的所有选项都可以与Clang一起使用,有些则被忽略.以上链接到libc ++,它是使用Clang的Mac OS X的首选C++标准库(比libstdc ++更完整(即使在考虑最新的GCC时).
至于出现这种情况的原因:我的魔术算命球告诉我你所说的g ++是一个古老的GCC 4.2.1 Apple的东西,有GCC的libstdc ++,几乎没有C++ 11的支持.Apple改用了Clang,现在更受欢迎.