2
我想弄清楚如何使用即將到來的C++版本0x。它應該可以在GCC 4.3+中使用gcc std = gnu ++ 0x選項。如何在Eclipse CDT中使用GCC/G ++編譯並運行C++ 0x?
我在Eclipse CDT中使用0x編譯的簡單線程程序,在std = gnu ++ 0x中添加了Project> properties> C/C++ Build> Settings> Miscellaneous> Other flags。
#include <iostream>
#include <thread>
using namespace std;
void hello()
{
cout << "Hello Concurrent World!" << endl;
}
int main()
{
cout << "starting" << endl;
thread t(hello);
t.join();
cout << "ending" << endl;
return 0;
}
該程序只打印「開始」,並返回0.有誰知道爲什麼它不運行hello函數線程?
您已經添加了'-pthread'標誌,給鏈接器和編譯器? – nos 2010-07-04 17:13:05
不錯,向鏈接器添加-pthread標誌並且編譯器執行它。非常感謝。 – davidhalldor 2010-07-04 17:17:14
添加此爲答案,以便我可以投票! – mmocny 2011-03-03 20:09:41