Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'mutex' is not a member of 'std' in MinGW 5.3.0

I am using MinGW 5.3.0 and Crypto++ 5.6.5:

C:\MinGW>g++ -std=c++11 -s -D_WIN32_WINNT=0x0501 LOG.cpp -U__STRICT_ANSI__ Decclass.cpp \
-IC:\\MinGW\\ -IC:\\MinGW\\boost -LC:\\MinGW  -lssl -lcrypto -lcryptopp -lgdi32 -lPCRYPT \
 -lz -ltiny -lwsock32 -lws2_32 -lShlwapi

Compiling results in the error below.

c:\mingw\cryptopp565\include\cryptopp\misc.h:287:14: error: 'mutex' in namespace 'std'
does not name a typestatic std::mutex s_mutex;

c:\mingw\cryptopp565\include\cryptopp\misc.h:296:18: error: 'mutex' is not a member of
'std'std::lock_guard<std::mutex> lock(s_mutex);

enter image description here

It showing 'mutex' is not a member of 'std'

Do i need anther version of MinGW ? Or can I fix this build itself?

like image 227
Amit.Desai Avatar asked May 09 '17 07:05

Amit.Desai


2 Answers

I fix this issue by editing "misc.h" in the path "cryptopp565\include\cryptopp\misc.h"

On the top of misc.h I included the mutex.hpp from boost library

#include "c:\mingw\include\boost\asio\detail\mutex.hpp"

and i changed namespace also from std to boost::asio::detail

static std::mutex s_mutex; 
static boost::asio::detail::mutex s_mutex;
like image 174
Amit.Desai Avatar answered Oct 26 '22 06:10

Amit.Desai


MINGW supports std::thread and std::mutex with POSIX threads only, definitely a gap of the non-POSIX-release.

Now, you do not switch your development environment for a single program.

Options are to build stubs from POSIX specific templates (those code branches selected by _GLIBCXX_HAS_GTHREADS) or MS-Sources or BOOST library ...

like image 26
Sam Ginrich Avatar answered Oct 26 '22 05:10

Sam Ginrich