2013-05-11 72 views
0

我試圖安裝的cygwin編譯一個64位的Windows 7機器上下面的程序和 gcc編譯器更新到4.7.3:cygwin上的gcc 4.7.3支持C++ 11併發功能嗎?

#include <vector> 
#include <thread> 
#include <mutex> 

using namespace std; 

std::mutex flemutex; 
std::mutex arrmutex; 

main() { 

thread t; 
} 

在用下面的命令編譯:

gcc -std=c++11 -o file.o -c file.cpp 

我收到以下錯誤:

file.cpp:12:1: error: ‘mutex’ in namespace ‘std’ does not name a type 
file.cpp:13:1: error: ‘mutex’ in namespace ‘std’ does not name a type 
file.cpp: In function ‘int main()’: 
file.cpp:39:3: error: ‘thread’ is not a member of ‘std’ 
file.cpp:39:15: error: expected ‘;’ before ‘t’ 

有誰知道怎麼回事?

謝謝!

+0

(1)您是否嘗試將'-lpthread'添加到gcc的命令行? (2)你可以下載MinGW,它不需要cygwin並且可以使用線程「from the box」 – borisbn 2013-05-11 13:11:59

+0

我嘗試在命令行中添加-lpthread,但它不起作用。無論如何,我只是在這裏編譯,沒有鏈接,所以不應該有任何影響,對吧?另外,我希望這可以在cygwin上運行,並且不必在我的機器上安裝MinGW。兩者能否在同一臺機器上和平共處? – user2358643 2013-05-11 13:44:39

+0

簡單 - 更新cygwin和gcc。 – ikh 2014-04-07 11:26:53

回答

1

你可以嘗試以下方法:

#include <thread> 
#include <iostream> 

using std::cout; 
using std::endl; 

main() { 
#ifndef(_GLIBCXX_HAS_GTHREADS) 
    cout << "GThreads are not supported..." << endl; 
#endif 
} 

事實上,由於GCC 4.4,_GLIBCXX_HAS_GTHREADS是不確定的,當libstdc++建成因爲Cygwin的實施pthread缺少一些功能。 MinGW也是如此。

注意: GThreads,直接由std::thread使用,是圍繞POSIX線程的GCC包裝。

builds of MinGW-w64基於GCC 4.7和4.8靶向的64位和32位,這提供std::thread實驗支持。此外,當然Cygwin和MinGW可以共存,只要您在這兩個環境之間正確切換,即而不是將它們混合在PATH環境變量中。

相關鏈接:

+0

謝謝!這非常有幫助。 – user2358643 2013-05-12 13:34:08