How to use std :: thread in C ++ 11 under Cygwin GCC 4.7.2

I am trying to compile a multi-threaded hello-world program under Cygwin using the recently introduced C ++ 11 std :: thread function without success. I myself compiled and installed GCC 4.7.2, and the same code works without any problems on Linux with the same version of GCC. The first error I received was that the compiler did not recognize the -pthread flag. After studying for a while, I noticed that someone said about Cygwin, this flag should be -lthread. I made changes and this error disappeared, but there was another series of errors saying that the stream is not a member of std. I wonder if this is caused by a wrong compiler configuration during installation, or is std :: thread simply not supported in Cygwin?

+7
source share
1 answer

It seems that you did not compile the program with the corresponding standard library flag. If you want to compile for C ++ 11, you should use:

g++ --std=c++0x -o ... 

The --std flag sets the appropriate level of language compatibility. If this does not help, send error messages that you received as a list of sources.

-one
source

All Articles