Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

gcc - MinGW 4.8.1 C++11 thread support

I downloaded the version of MinGW from the official website: http://sourceforge.net/projects/mingw/files/ and installed it on my Windows 7 machine.

Running g++ --version gives me g++.exe (GCC) 4.8.1 and I believe GCC 4.8.1 has support for C++11 features, including threads.

Running g++ -std=c++11 main.cpp successfully compiles the following program.

//main.cpp
#include <memory>

int main() {
    std::unique_ptr<int> a(new int);
    return 0;
}

But running g++ -std=c++11 main.cpp on the following program:

//main.cpp
#include <mutex>

int main() {
    std::mutex myMutex;
    return 0;
}

gives errors:

main.cpp: In function `int main()`:
main.cpp:5:5: error: 'mutex' is not a member of 'std'
    std::mutex myMutex;
    ^
main.cpp:5:16: error: expected ';' before 'myMutex'
    std::mutex myMutex;
                ^

as if <mutex> is not supported. The compiler does not complain about #include <mutex> so I have no idea why I'm getting this error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If I understand well, std threading is still not supported on mingw, but some mingw-w64 builds support it. Fortunately, you can still build 32-bit apps using this version of mingw.

Here is the link for the builds.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...