Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MinGW 4.8.1 C++11 thread support

Tags:

gcc

c++11

g++

mingw

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.

like image 965
newprogrammer Avatar asked Jun 03 '14 07:06

newprogrammer


People also ask

Does G ++ 4.8 5 support C ++ 11?

Status of Experimental C++11 Support in GCC 4.8 GCC provides experimental support for the 2011 ISO C++ standard. This support can be enabled with the -std=c++11 or -std=gnu++11 compiler options; the former disables GNU extensions.

Does GCC 4.8 support C ++ 17?

According to cppreference, full support of c++11 came with gcc 4.8. 1; To have full support of c++14 (with some of the new features of c++17), instead, you need gcc 5.0 and above.

Does GCC 5.4 support C ++ 17?

C++17 features are available since GCC 5.

What compiler does MinGW use?

What is MinGW? MinGW is a compiler system based on the GNU GCC and Binutils projects that compiles and links code to be run on Win32 (Windows) systems. It provides C, C++ and Fortran compilers plus other related tools.


2 Answers

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.

like image 82
slaadvak Avatar answered Oct 05 '22 15:10

slaadvak


There is already a native win32 implementation of std::thread and sync primitives: https://github.com/meganz/mingw-std-threads It is a header-only library and should work with any C++11 compliant version of MinGW.

like image 25
Alexander Vassilev Avatar answered Oct 05 '22 15:10

Alexander Vassilev