2013-05-11 59 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