I’m writing a simple C++ program to demonstrate the use of locks. I am using codeblocks
and gnu
gcc
compiler.
#include <iostream>
#include <thread>
#include <mutex>
using namespace std;
int x = 0; // shared variable
void synchronized_procedure()
{
static std::mutex m;
m.lock();
x = x + 1;
if (x < 5)
{
cout<<"hello";
}
m.unlock();
}
int main()
{
synchronized_procedure();
x=x+2;
cout<<"x is"<<x;
}
I’m getting the following error: mutex in namespace std does not name a type
.
Why am I getting this error?
Doesn’t the compiler support use of locks?
Parker
6,99712 gold badges71 silver badges89 bronze badges
asked Jan 7, 2013 at 7:21
5
I happened to be looking at the same problem. GCC works fine with std::mutex
under Linux. However, on Windows things seem to be worse. In the <mutex> header file shipped with MinGW GCC 4.7.2 (I believe you are using a MinGW GCC version too), I have found that the mutex class is defined under the following #if
guard:
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
Regretfully, _GLIBCXX_HAS_GTHREADS
is not defined on Windows. The runtime support is simply not there.
You may also want to ask questions directly on the MinGW mailing list, in case some GCC gurus may help you out.
EDIT: The MinGW-w64 projects provides the necessary runtime support. Check out http://mingw-w64.sourceforge.net/ and https://sourceforge.net/projects/mingw-w64/files/. Also, as 0xC0000022L pointed out, you need to download the POSIX thread version (I missed mentioning it last time).
answered Aug 1, 2013 at 6:35
Yongwei WuYongwei Wu
5,06636 silver badges48 bronze badges
1
Use POSIX threading model for MINGW:
$ sudo update-alternatives --config i686-w64-mingw32-gcc
<choose i686-w64-mingw32-gcc-posix from the list>
$ sudo update-alternatives --config i686-w64-mingw32-g++
<choose i686-w64-mingw32-g++-posix from the list>
$ sudo update-alternatives --config x86_64-w64-mingw32-gcc
<choose x86_64-w64-mingw32-gcc-posix from the list>
$ sudo update-alternatives --config x86_64-w64-mingw32-g++
<choose x86_64-w64-mingw32-g++-posix from the list>
See also: mingw-w64 threads: posix vs win32
answered Nov 28, 2018 at 21:26
Amir SaniyanAmir Saniyan
12.7k20 gold badges87 silver badges134 bronze badges
2
This has now been included in MingW (Version 2013072300). To include it you have to select the pthreads package in the MinGW Installation Manager.
answered Jun 15, 2015 at 15:47
IsakBosmanIsakBosman
1,42512 silver badges19 bronze badges
3
Mutex, at least, is not supported in ‘Thread model: win32’ of the Mingw-builds toolchains. You must select any of the toolchains with ‘Thread model: posix’. After trying with several versions and revisions (both architectures i686 and x86_64) I only found support in x86_64-4.9.2-posix-seh-rt_v3-rev1 being the thread model, IMO, the determining factor.
answered Dec 23, 2014 at 0:44
I encountered this same problem when using MingW-W64 7.2.0. I tested out several different Windows builds from the mingw-64 download page, and found that MinGW-W64 GCC-8.1.0 supports mutex
and contains the pthread
library. When installing, I selected the following options:
- x86_64
- posix
- seh
My multi-threaded code based on pthreads
now compiles and runs cleanly on both Windows and Linux with no changes.
This version is leaner than the 7.3.0 build I was using because it doesn’t have a CygWin environment or package manager. I also copied mingw32-make.exe
to make.exe
so my Makefile wouldn’t need to be modified. The installer creates a «Run terminal» link in the Windows Start Menu.
answered Nov 18, 2018 at 16:47
ParkerParker
6,99712 gold badges71 silver badges89 bronze badges
1
I got the same error with gcc4.7.7.
After adding «-std=c++0x», it is fixed.
answered Dec 4, 2017 at 4:44
1
my gcc version is 5.4 and i solved this problem when adding #include and also adding -std=c++11 at my CmakeLists.txt as below:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native -std=c++11")
answered Dec 26, 2019 at 1:44
Nan ShiNan Shi
551 gold badge1 silver badge6 bronze badges
I fixed it by following steps:
- Project > Build option…
- The default selected compiler: GNU GCC Compiler
- On tab «Compiler settings / Compiler flags», check option
«Have g++ follow the C++11 ISO C++ language standard [-std=c++11]»
Dharman♦
29.3k21 gold badges80 silver badges131 bronze badges
answered Sep 28, 2017 at 6:25
I don’t know if it works for everybody, but in other way you just have to update your ndk. I’m using ndk-r11c and it works perfectly.
answered Jun 3, 2016 at 8:14
BastienmBastienm
3132 silver badges16 bronze badges
3
Many classes of the standard thread library can be replaced with the boost ones. A very easy workaround is to change the entire standard mutex
file with a couple of lines.
#include <boost/thread.hpp>
namespace std
{
using boost::mutex;
using boost::recursive_mutex;
using boost::lock_guard;
using boost::condition_variable;
using boost::unique_lock;
using boost::thread;
}
And do not forget to link against boost thread library.
answered Jul 3, 2013 at 5:43
KolyunyaKolyunya
5,8707 gold badges44 silver badges80 bronze badges
2
When I am try the following code in ubuntu with arm-none-eabi-g++ tool chain i was getting compilation errors:
#include <iostream>
#include <thread> // std::thread
#include <mutex> // std::mutex
mutex mtx; // mutex for critical section
int main ()
{
return 0;
}
commpile command :
arm-none-eabi-g++ -Os -Wall -std=c++11 -fno-rtti -fno-exceptions -c mt.cc
compile error:
mt.cc:5:1: error: ‘mutex’ does not name a type mutex mtx; //
mutex for critical section
^
gcc version:
gcc version 4.8.4 20140725 (release) [ARM/embedded-4_8-branch revision 213147] (GNU Tools for ARM Embedded Processors)
Biffen
6,1736 gold badges30 silver badges35 bronze badges
asked Mar 18, 2016 at 11:16
4
You got the comment right:
#include <mutex> // std::mutex
But then you didn’t get the code right:
mutex mtx; // mutex for critical section
That should be std::mutex
answered Mar 18, 2016 at 12:06
Jonathan WakelyJonathan Wakely
164k24 gold badges333 silver badges514 bronze badges
3
0
1
Что это вообще за зверь и с чем его едят? Гугл находит только шаманства, которые помогали людям в их специфических ситуациях (например, попытку задействовать как std::mutex реализацию из библиотеки boost), и поспешные оправдания в том, что это, мол, «local issue». А что за «local issue» и почему — нигде ничего не находится.
/usr/include/c++/6.2.0/bits/std_mutex.h на месте, в /usr/include/c++/6.2.0/mutex он упомянут, и «#include <mutex>» в исходниках (кстати, эмулятора MAME) совсем не забыто. Правда, там есть проверка на версию стандарта, но компилятор вызывается с «-std=c++14» и всё равно падает:
# make
GCC 6.2.0 detected
Precompiling src/emu/emu.h...
In file included from ../../../../../src/emu/emucore.h:37:0,
from ../../../../../src/emu/emu.h:29:
../../../../../src/emu/emualloc.h:128:7: ошибка: <<mutex>> в пространстве имен <<std>> не именует тип
std::mutex m_listlock;
^~~~~
make[2]: *** [precompile.make:270: ../../../../linux_gcc/obj/x64/Release/emu.h.gch] Ошибка 1
make[1]: *** [Makefile:55: precompile] Ошибка 2
make: *** [makefile:1170: linux_x64] Ошибка 2
Где может быть засада?
Environment info
Operating System:
windors10 64bit
CPU/GPU model:
C++/Python/R version:
MinGW64
gcc version 8.1.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)
LightGBM version or commit hash:
Error message
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:42:8: error: ‘mutex’ in namespace ‘std’ does not name a type
std::mutex lock_;
^~~~~
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:42:3: note: ‘std::mutex’ is defined in header »; did you forget to ‘#include ‘?
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:15:1:
+#include
#include
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:42:3:
std::mutex lock_;
^~~
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h: In member function ‘void ThreadExceptionHelper::CaptureException()’:
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:35:27: error: ‘mutex’ is not a member of ‘std’
std::unique_lockstd::mutex guard(lock_);
^~~~~
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:35:27: note: ‘std::mutex’ is defined in header »; did you forget to ‘#include ‘?
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:35:27: error: ‘mutex’ is not a member of ‘std’
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:35:27: note: ‘std::mutex’ is defined in header »; did you forget to ‘#include ‘?
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:35:32: error: template argument 1 is invalid
std::unique_lockstd::mutex guard(lock_);
^
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:35:40: error: In file included from ‘
‘ was not declared in this scope
std::unique_lockstd::mutex guard(C:/Users/Downloads/LightGBM/include/LightGBM/utils/common.h:9lock_);
,
from ^~~~~C:/Users/Downloads/LightGBM/include/LightGBM/config.h:13
,
from C:/Users/Downloads/LightGBM/include/LightGBM/application.h:8,
from C:UsersDownloadsLightGBMsrcmain.cpp:5C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:35:40::
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:42:8:note: suggested alternative: ‘error: clock»
std::unique_lockstd::mutex guard(mutexlock_’ in namespace ‘);
std^~~~~’ does not name a type
std::
mutexclock lock_;
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:35:34: warning: ^~~~~unused variable ‘
C:/Users/Downloads/LightGBM/include/LightGBM/utils/openmp_wrapper.h:42:3:guard ‘ [note: -Wunused-variable’]
std::unique_lockstd::mutex guardstd::mutex’ is defined in header ‘(lock_);
^~~~~’; did you forget to ‘
#include ‘?
Reproducible examples
Steps to reproduce
Does windows not support mutex? How should I fix this?
- Forum
- General Programming Boards
- C++ Programming
- g++ 4.7.2 error: ‘mutex’ in namespace ‘std’ does not name a type
-
03-11-2013
#1
Registered User
g++ 4.7.2 error: ‘mutex’ in namespace ‘std’ does not name a type
I’ve verified this on ubuntu 12.10 and on windows/mingw, and found that g++ version 4.7.2 seems to have broken thread/mutex support. has anyone else observed this?
-
03-11-2013
#2
and the hat of int overfl
Can you post your test case?
-
03-11-2013
#3
Master Apprentice
has anyone else observed this?
I usually build my own package for «Windows», so maybe it is just my builds script, but that seems par for the course under «MinGW».
I can’t speak to anything about «Ubuntu».
My understanding, and only that, is that a lot of work needs to be done for «libstdc++» before the implementation has the proper safety the respect to the standard. You may not, and probably will not, be able to match your own expectations with «libstdc++» for a bit longer.
Soma
-
03-11-2013
#4
Registered User
Originally Posted by Salem
Can you post your test case?
this was my actual test case
Code:
#include <iostream> #include <thread> #include <vector> #include <memory> std::mutex mutex; int mutexProtected = 0; void threadProc() { for (int i = 0; i < 5; ++i) { std::lock_guard<std::mutex> lock(mutex); std::cout << "Value: " << ++mutexProtected << std::endl; } } int main() { std::vector<std::shared_ptr<std::thread> > threadVector; for (int i = 0; i < 20; ++i) { threadVector.push_back(std::shared_ptr<std::thread>(new std::thread(threadProc))); } for (auto& thread : threadVector) { thread->join(); } return 0; }
my compile command is
Code:
g++ -pthread -std=c++0x -c main.cpp
and the output I get on mingw is
Code:
main.cpp:6:1: error: 'mutex' in namespace 'std' does not name a type main.cpp: In function 'void threadProc()': main.cpp:13:2: error: 'lock_guard' is not a member of 'std' main.cpp:13:18: error: 'mutex' is not a member of 'std' main.cpp:13:35: error: 'mutex' was not declared in this scope main.cpp:13:40: error: 'lock' was not declared in this scope main.cpp: In function 'int main()': main.cpp:22:33: error: 'thread' is not a member of 'std' main.cpp:22:33: error: 'thread' is not a member of 'std' main.cpp:22:44: error: template argument 1 is invalid main.cpp:22:46: error: template argument 1 is invalid main.cpp:22:46: error: template argument 2 is invalid main.cpp:22:60: error: invalid type in declaration before ';' token main.cpp:26:15: error: request for member 'push_back' in 'threadVector', which is of non-class type 'int' main.cpp:26:41: error: 'thread' is not a member of 'std' main.cpp:26:41: error: 'thread' is not a member of 'std' main.cpp:26:52: error: template argument 1 is invalid main.cpp:26:58: error: expected type-specifier main.cpp:26:58: error: expected ')' main.cpp:29:25: error: no matching function for call to 'begin(int&)' more errors snipped...
even a simple test case like this exhibits essentially the same behavior
Code:
#include <mutex> int main() { std::mutex mutex; return 0; }
there were many more errors, but they were all related to the compiler’s inability to find a begin() or end() function for std::vector<std::shared_ptr<std::thread> >.
after more digging, I determined that on ubuntu, modifying the code to include <mutex> solved the problem. it seems that <mutex> was included implicitly by <thread> in g++ 4.6.3 on fedora 15, and a recent move to ubuntu 12.10 (gcc 4.7.3) for my main dev machine exposed that fact.
on mingw (gcc 4.7.3), including <mutex> did not solve the problem. it appears that the std::thread implementation in the official release of mingw version of g++ 4.7.3 is incomplete or nonexistent.
-
03-11-2013
#5
Registered User
You may want to include <mutex> to use the mutex class. After I add that include file your program compiles without errors for me. But I do use the -std=c++11 flag instead of -std=c++0x.
Jim
-
03-11-2013
#6
Registered User
Originally Posted by jimblumberg
You may want to include <mutex> to use the mutex class. After I add that include file your program compiles without errors for me.
as I said in my last post, that fixes it on ubuntu, but not on windows.
Originally Posted by jimblumberg
But I do use the -std=c++11 flag instead of -std=c++0x.
changing -std=c++0x to -std=c++11 makes no difference. my guess is that they are equivalent.
-
03-11-2013
#7
Registered User
changing -std=c++0x to -std=c++11 makes no difference. my guess is that they are equivalent.
Not on my system. If I change to -std=c++0x I get these errors:
/usr/include/c++/4.7/bits/c++0x_warning.h|32|error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.|
main.cpp||In function ‘int main()’:|
main.cpp|5|error: ‘mutex’ is not a member of ‘std’|
main.cpp|5|error: expected ‘;’ before ‘mutex’|
||=== Build finished: 3 errors, 0 warnings ===|Jim
-
03-11-2013
#8
Registered User
Originally Posted by jimblumberg
changing -std=c++0x to -std=c++11 makes no difference. my guess is that they are equivalent.
Not on my system. If I change to -std=c++0x I get these errors:
Jim
what actual version of gcc is it? (gcc —version)
-
03-11-2013
#9
Registered User
-
03-11-2013
#10
Registered User
that’s interesting. both produce identical results on my ubuntu and mingw systems with 4.7.3.
-
03-11-2013
#11
Registered User
In my Code::Blocks with MinGW GCC (gcc version 4.7.1 (tdm-1)),
_GLIBCXX_HAS_GTHREADS is not defined.From mutex header.
Code:
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) namespace std _GLIBCXX_VISIBILITY(default) {
I am guessing that there is a option that compiles MinGW GCC with this _GLIBCXX_HAS_GTHREADS defined.
Tim S.
«…a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match..» Bill Bryson
-
03-13-2013
#12
Registered User
MinGW-w64 does support C++11 threads, and despite its name, it is also for 32-bit (which I personally use):
GCC for both x64 & x86 Windows! — MinGW-w64
Popular pages
- Exactly how to get started with C++ (or C) today
- C Tutorial
- C++ Tutorial
- 5 ways you can learn to program faster
- The 5 Most Common Problems New Programmers Face
- How to set up a compiler
- 8 Common programming Mistakes
- What is C++11?
- Creating a game, from start to finish
Recent additions
- How to create a shared library on Linux with GCC — December 30, 2011
- Enum classes and nullptr in C++11 — November 27, 2011
- Learn about The Hash Table — November 20, 2011
- Rvalue References and Move Semantics in C++11 — November 13, 2011
- C and C++ for Java Programmers — November 5, 2011
- A Gentle Introduction to C++ IO Streams — October 10, 2011
Similar Threads
-
Replies: 4
Last Post: 05-01-2011, 12:37 PM
-
Replies: 4
Last Post: 11-12-2010, 06:07 PM
-
Replies: 10
Last Post: 05-12-2006, 11:53 PM
-
Replies: 0
Last Post: 04-26-2006, 01:56 PM
-
Replies: 12
Last Post: 08-30-2001, 07:14 AM

Author
Topic: ‘ mutex ‘ in namespace ‘ std ‘ does not name a type (Read 10365 times)
Good all day! Error-D:Classesmutex1mutex1.cpp | 9 | error: ‘ mutex ‘ in namespace ‘ std ‘ does not name a type |
Something is wrong with my compiler. So far, everything has always been well compiled, worked remarkably well.
Various advice and research problems I accept with joy.
Downloaded D: gcc-6.3.0 gcc-6.3.0 (gcc-6.3.0.tar.bz2)
It can somehow be connected in the right places?
Is not it necessary to compile something at first?
In general, I imagine the steps of correcting the problem rather poorly. What additional libraries are available?
« Last Edit: August 05, 2017, 10:05:04 pm by Дмитро »
Logged
« Last Edit: August 05, 2017, 11:23:51 pm by BlueHazzard »
Logged
Yes, thank you very much for clarifying!
Yes, I see, it seems, a problem with the compiler.
Precisely, for certain with the compiler some problems.
So I’ll try to compile gcc-6.3.0.
If I understand correctly, I will need to compile it using msys, surely it.
Msys I have, but I’ve never, before any successful compilation of it, never before complex
Never before did compilation fail.
I now measure, in general, this problem.
« Last Edit: August 06, 2017, 03:25:14 pm by Дмитро »
Logged
you can still post a full rebuild log. Can it be you forget the —std=c++11 compiler flag?
Logged
Setting up the environment for Mingw-w64 may look easy and straightforward, but choosing the wrong setting during the setup may lead to failure to build or compile the source code. For example, if the source code contains the usage of mutex. With the wrong installation settings for Mingw-w64, you may stumble upon similar errors that are shown below.
error: ‘mutex’ in
namespace ‘std’ does not name a type
std::mutex m_mutex;
note: ‘std::mutex’
is defined in header ‘<mutex>’; did you forget to ‘#include
<mutex>’?
error: ‘mutex’ is
not a member of ‘std’
std::lock_guard<std::mutex>
lock(m_mutex);
error: template
argument 1 is invalid
std::lock_guard<std::mutex>
lock(m_mutex);
error: ‘m_mutex’ was
not declared in this scope
std::lock_guard<std::mutex>
lock(m_mutex);
note: suggested
alternative: ‘uv_mutex_t’
std::lock_guard<std::mutex>
lock(m_mutex);
^~~~~~~
uv_mutex_t
warning: unused variable ‘lock’
[-Wunused-variable]
std::lock_guard<std::mutex>
lock(m_mutex);
This is due to the settings that you specified during the installation doesn’t contain the mutex implementation. So to fix this, you need to reinstall with the correct setting, where the mutex implementation is in the posix. Rerun the Mingw-w64 installer and make sure the posix is selected for the threads and continue with the installation.
Do take note to update the %PATH% Environment Variables to the newly installed path of Mingw-w64 with posix and restart your command prompt session to ensure the command is picking up the correct settings.
|
#1 | Link |
Registered User
Join Date: Nov 2005 Posts: 684 |
«error: ‘mutex’ in namespace ‘std’ does not name a type» despite up-to-date toolchain I’m using ‘mingw-w64-build-r25’ from https://files.1f0.de/mingw/scripts/ (does anyone know who actually maintains these updated scripts? Hendrik / nevairiel?) to create my own toolchain with GCC 8.2, MinGW-w64 6.0.0 and pthreads 2.9.1. Today I tried to compile libdmusic, but I got the following error: Code: [ 11%] Building CXX object CMakeFiles/dmusic.dir/src/DlsPlayer.cpp.obj In file included from /[...]/libdmusic_git/include/dmusic/DlsPlayer.h:8, from /[...]/libdmusic_git/src/DlsPlayer.cpp:1: /[...]/libdmusic_git/include/dmusic/PlayingContext.h:74:14: error: 'mutex' in namespace 'std' does not name a type std::mutex m_queueMutex; ^~~~~ I’ve done some searching and read that std::mutex and std::thread are added in C++11, which requires a recent GCC version and most likely the -std=gnu++11 compiler flag as well. |
|
|
|
#2 | Link |
Software Developer
Join Date: Jun 2005 Location: Last House on Slunk Street Posts: 13,243 |
std::mutex is indeed a C++11 feature. But I think «-std=gnu++14» is GCC’s default for C++ code by now: Anyhow, whether setting CXXFLAGS or CFLAGS has any effect, that totally depends on the build system (e.g. Makefile) that is used to build the application! Also, make sure that your MinGW was built with «posix» threading (libwinpthread). If built with «win32» threading, C++11 threading features are not available! More info on that topic here:
Last edited by LoRd_MuldeR; 23rd December 2018 at 21:47.
|
|
|
|
#3 | Link |
Registered User
Join Date: Nov 2005 Posts: 684 |
Quote:
Originally Posted by LoRd_MuldeR whether setting CXXFLAGS or CFLAGS has any effect, that totally depends on the build system (e.g. Makefile) that is used to build the application! libdmusic is built with cmake. In ‘CMakeCache.txt’ at least I can see: Code: //Flags used by the CXX compiler during all build types. CMAKE_CXX_FLAGS:STRING=-std=gnu++14 Quote:
Originally Posted by LoRd_MuldeR Also, make sure that your MinGW was built with «posix» threading (libwinpthread). If built with «win32» threading, C++11 threading features are not available! Code: $ ./mingw-w64-build-r25 --help [...] Compile Options: [...] --threads=LIB compile with support for thread LIB (winpthreads, pthreads-w32, disable) [pthreads-w32] As this script defaults to pthreads-w32, I’ve (successfully) rebuilt my toolchain with winpthreads this time. (libwinpthread == winpthreads, right?) |
|
|
|
#4 | Link |
Software Developer
Join Date: Jun 2005 Location: Last House on Slunk Street Posts: 13,243 |
Try «g++ -v» and check the output. Should be something like this: Quote: $ g++ -v The following example program compiles without problem here, using the above MinGW/GCC: (BTW: Why not simply grab MinGW/GCC via MSYS2? This is what I’m using now exclusively)
Last edited by LoRd_MuldeR; 25th December 2018 at 14:01.
|
|
|
|
#5 | Link |
Registered Developer Join Date: Mar 2010 Location: Hamburg/Germany Posts: 10,266 |
Its a shame that they don’t want to implement the stuff with native threading. winpthreads is kinda crappy. https://github.com/meganz/mingw-std-threads
__________________
Last edited by nevcairiel; 25th December 2018 at 20:02.
|
|
|
|
#6 | Link |
Registered User
Join Date: Nov 2005 Posts: 684 |
Quote:
Originally Posted by LoRd_MuldeR Try «g++ -v» and check the output. Code: $ ./i686-w64-mingw32-g++.exe -v Using built-in specs. COLLECT_GCC=./i686-w64-mingw32-g++ COLLECT_LTO_WRAPPER=/[...]/cross_compilers/mingw-w64-i686/libexec/gcc/i686-w64-mingw32/8.2.0/lto-wrapper.exe Target: i686-w64-mingw32 Configured with: ../source/gcc-8.2.0/configure --build=i686-pc-cygwin --target=i686-w64-mingw32 --disable-shared --enable-static --disable-nls --disable-multilib --prefix=/[...]/cross_compilers/mingw-w64-i686 --with-sysroot=/[...]/cross_compilers/mingw-w64-i686 --with-mpc=/[...]/cross_compilers/pkgs/mpc/mpc-1.1.0-i686 --with-mpfr=/[...]/cross_compilers/pkgs/mpfr/mpfr-4.0.1-i686 --with-gmp=/[...]/cross_compilers/pkgs/gmp/gmp-6.1.2-i686 --with-isl=/[...]/cross_compilers/pkgs/isl/isl-0.20-i686 --enable-languages=c,c++ --enable-fully-dynamic-string --enable-lto Thread model: win32 gcc version 8.2.0 (GCC) I’ve tried to rerun the script with —enable-threads=posix … Code: diff --git a/patches/mingw-w64-build-r25 b/patches/mingw-w64-build-r25 index d43cbd5..007ce53 100755 --- a/patches/mingw-w64-build-r25 +++ b/patches/mingw-w64-build-r25 @@ -317,7 +317,7 @@ fi case "$gcc_ver" in $gcc_old_release_ver ) CC=$gcc "../source/gcc-$gcc_ver/configure" --build="$system_type" --target="$mingw_w64_target" "${static_build[@]}" "${disable_nls[@]}" --disable-multilib --prefix="$mingw_w64_prefix" --with-sysroot="$mingw_w64_prefix" --with-mpc="$mpc_prefix" --with-mpfr="$mpfr_prefix" --with-gmp="$gmp_prefix" --with-host-libstdcxx="-lstdc++" --with-cloog="$cloog_prefix" --with-isl="$isl_prefix" --enable-languages="$enabled_langs" --enable-fully-dynamic-string --enable-lto > >(build_log) 2>&1 ;; - $gcc_release_ver ) CC=$gcc "../source/gcc-$gcc_ver/configure" --build="$system_type" --target="$mingw_w64_target" $gcc_host "${static_build[@]}" "${disable_nls[@]}" --disable-multilib --prefix="$mingw_w64_prefix" --with-sysroot="$mingw_w64_prefix" --with-mpc="$mpc_prefix" --with-mpfr="$mpfr_prefix" --with-gmp="$gmp_prefix" --with-isl="$isl_prefix" --enable-languages="$enabled_langs" --enable-fully-dynamic-string --enable-lto > >(build_log) 2>&1 || print_error ;; + $gcc_release_ver ) CC=$gcc "../source/gcc-$gcc_ver/configure" --build="$system_type" --target="$mingw_w64_target" $gcc_host "${static_build[@]}" "${disable_nls[@]}" --disable-multilib --prefix="$mingw_w64_prefix" --with-sysroot="$mingw_w64_prefix" --with-mpc="$mpc_prefix" --with-mpfr="$mpfr_prefix" --with-gmp="$gmp_prefix" --with-isl="$isl_prefix" --enable-languages="$enabled_langs" --enable-fully-dynamic-string --enable-lto --enable-threads=posix > >(build_log) 2>&1 || print_error ;; esac } … but that didn’t work out: Code: /[...]/cross_compilers/pkgs/gcc/build/./gcc/xgcc -B/[...]/cross_compilers/pkgs/gcc/build/./gcc/ -L/[...]/cross_compilers/mingw-w64-i686/i686-w64-mingw32/lib -L/[...]/cross_compilers/mingw-w64-i686/mingw/lib -isystem /[...]/cross_compilers/mingw-w64-i686/i686-w64-mingw32/include -isystem /[...]/cross_compilers/mingw-w64-i686/mingw/include -B/[...]/cross_compilers/mingw-w64-i686/i686-w64-mingw32/bin/ -B/[...]/cross_compilers/mingw-w64-i686/i686-w64-mingw32/lib/ -isystem /[...]/cross_compilers/mingw-w64-i686/i686-w64-mingw32/include -isystem /[...]/cross_compilers/mingw-w64-i686/i686-w64-mingw32/sys-include -g -O2 -O2 -I../../../source/gcc-8.2.0/libgcc/../winsup/w32api/include -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -I. -I. -I../.././gcc -I../../../source/gcc-8.2.0/libgcc -I../../../source/gcc-8.2.0/libgcc/. -I../../../source/gcc-8.2.0/libgcc/../gcc -I../../../source/gcc-8.2.0/libgcc/../include -I../../../source/gcc-8.2.0/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_EMUTLS -o unwind-dw2.o -MT unwind-dw2.o -MD -MP -MF unwind-dw2.dep -fexceptions -c ../../../source/gcc-8.2.0/libgcc/unwind-dw2.c In file included from ../../../source/gcc-8.2.0/libgcc/gthr.h:148, from ../../../source/gcc-8.2.0/libgcc/unwind-dw2.c:37: ./gthr-default.h:35:10: fatal error: pthread.h: No such file or directory #include <pthread.h> ^~~~~~~~~~~ compilation terminated. make[1]: *** [../../../source/gcc-8.2.0/libgcc/static-object.mk:17: unwind-dw2.o] Error 1 make[1]: Leaving directory '/[...]/cross_compilers/pkgs/gcc/build/i686-w64-mingw32/libgcc' make: *** [Makefile:12735: all-target-libgcc] Error 2 Quote:
Originally Posted by LoRd_MuldeR (BTW: Why not simply grab MinGW/GCC via MSYS2? This is what I’m using now exclusively) The toolchain that the ‘mingw-w64-build-r25’ script produces is the only toolchain I have yet experience with. I’m still relatively new to this. |
|
|
|
#7 | Link |
Software Developer
Join Date: Jun 2005 Location: Last House on Slunk Street Posts: 13,243 |
Quote:
Originally Posted by CoRoNe The toolchain that the ‘mingw-w64-build-r25’ script produces is the only toolchain I have yet experience with. I’m still relatively new to this. Just install MYSY2 from here (you probably want 64-Bit these days). Then start MSYS2 shell and run «pacman -Syu«, restart MSYS2 shell, run «pacman -Su«, and restart MSYS2 shell again. Finally, run « pacman -S mingw-w64-i686-toolchain» or «pacman -S mingw-w64-x86_64-toolchain» to install MinGW/GCC targeting 32-Bit or 64-Bit, respectively. That’s it
Last edited by LoRd_MuldeR; 31st December 2018 at 13:54.
|
|
|
|
#8 | Link |
SuperVirus
Join Date: Jun 2012 Location: Antarctic Japan Posts: 1,316 |
Quote:
Originally Posted by LoRd_MuldeR Finally, run «pacman -S mingw-w64-i686-toolchain» or «pacman -S mingw-w64-x86_64-toolchain» to install MinGW/GCC targeting 32-Bit or 64-Bit, respectively. That’s it That’s simple, but it’s not as smart as it may seem. So I recommend these command-lines: 1) pacman -S mingw-w64-i686-binutils mingw-w64-i686-crt-git mingw-w64-i686-gcc mingw-w64-i686-gcc-libs 2) pacman -S mingw-w64-x86_64-binutils mingw-w64-x86_64-crt-git mingw-w64-x86_64-gcc mingw-w64-x86_64-gcc-libs And only if you absolutely need them: mingw-w64-i686-winstorecompat-git && mingw-w64-x86_64-winstorecompat-git, respectively.
Last edited by filler56789; 11th December 2019 at 06:32. Reason: update
|
|
|
- Forum
- General C++ Programming
- C++0x mutex don’t compile on minGW
C++0x mutex don’t compile on minGW
Hi,
I have this code:
|
|
myMutex is an instance of std::mutex, a new C++0x class for multithreading.
This code compiles fine on Linux with GCC/G++ 4.5.1, but under Window with minGW (GCC/G++) 4.5.2 I have this error on compiling:
error: ‘mutex’ does not name a type
Why?
Did you try
«#include <mutex>»
Tim S.
I wonder how many (tens of) years have to pass until they finally fix that header hell and provide true, first-class modularity. Even something like Pascal had 10 years ago would be a big step forward (but being able to selectively import things into the namespace would be better).
Last edited on
<thread> includes <mutex>.
But this is not the problem…
Is it possible that
std::mutex
support is completely missing from minGW? Have you tried the Boost Thread library to see if that works with minGW?
Yes, it is possible but it’s strange, the compiler version is the same as Linux.
I would not use boost.thread because I would not change anything in my code!
The C++0x thread library should be the same as the boost one.
The only difference is the namespace
@Bazzy: I’m not so sure. I seem to recall a post on the Boost mailing list about getting GSoC help to update the thread library to better match the C++0x draft standard.
Topic archived. No new replies allowed.