Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Programming and Hacking > Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 23rd December 2018, 16:01   #1  |  Link
Reino
Registered User
 
Reino's Avatar
 
Join Date: Nov 2005
Posts: 693
"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.
I'm using the latest GCC, but export CXXFLAGS="-std=gnu++11" didn't make any difference. I still get the error.
Now I wonder, is this guy right, despite having the latest GCC? Or is there a flaw in the MinGW-w64 build script that I'm getting this error?
__________________
My hobby website
Reino is offline   Reply With Quote
Old 23rd December 2018, 21:21   #2  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
std::mutex is indeed a C++11 feature. But I think "-std=gnu++14" is GCC's default for C++ code by now:
https://gcc.gnu.org/onlinedocs/gcc/C...ialect-Options

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!
For example, you may need to specify those when running the ./configure script, so that they will actually be applied to the generated Makefile.

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:
* https://stackoverflow.com/a/30390278
* https://wiki.qt.io/MinGW-64-bit#GCC_...ix_vs_win32.29
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 23rd December 2018 at 21:47.
LoRd_MuldeR is offline   Reply With Quote
Old 25th December 2018, 12:06   #3  |  Link
Reino
Registered User
 
Reino's Avatar
 
Join Date: Nov 2005
Posts: 693
Quote:
Originally Posted by LoRd_MuldeR View Post
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 View Post
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?)
Despite all the effort however I'm still getting the mutex error. I really don't understand why.
__________________
My hobby website
Reino is offline   Reply With Quote
Old 25th December 2018, 13:02   #4  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Try "g++ -v" and check the output. Should be something like this:
Quote:
$ g++ -v
Using built-in specs.
COLLECT_GCC=C:\msys64\mingw32\bin\g++.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../gcc-7.3.0/configure --prefix=/mingw32 --with-local-prefix=/mingw32/local --build=i686-w64-mingw32 --host=i686-w64-mingw32 --target=i686-w64-mingw32 --with-native-system-header-dir=/mingw32/i686-w64-mingw32/include --libexecdir=/mingw32/lib --enable-bootstrap --with-arch=i686 --with-tune=generic --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --enable-libstdcxx-filesystem-ts=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw32 --with-mpfr=/mingw32 --with-mpc=/mingw32 --with-isl=/mingw32 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld --disable-sjlj-exceptions --with-dwarf2
Thread model: posix
gcc version 7.3.0 (Rev2, Built by MSYS2 project)
The following example program compiles without problem here, using the above MinGW/GCC:
https://pastebin.com/aQ25Gcp0

(BTW: Why not simply grab MinGW/GCC via MSYS2? This is what I'm using now exclusively)
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 25th December 2018 at 14:01.
LoRd_MuldeR is offline   Reply With Quote
Old 26th December 2018, 15:39   #5  |  Link
Reino
Registered User
 
Reino's Avatar
 
Join Date: Nov 2005
Posts: 693
Quote:
Originally Posted by LoRd_MuldeR View Post
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 View Post
(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.
I might give it a try some day.
__________________
My hobby website
Reino is offline   Reply With Quote
Old 31st December 2018, 13:51   #6  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Quote:
Originally Posted by CoRoNe View Post
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.
I might give it a try some day.
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
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 31st December 2018 at 13:54.
LoRd_MuldeR is offline   Reply With Quote
Old 8th November 2019, 08:26   #7  |  Link
filler56789
SuperVirus
 
filler56789's Avatar
 
Join Date: Jun 2012
Location: Antarctic Japan
Posts: 1,351
Quote:
Originally Posted by LoRd_MuldeR View Post
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.
Downloading the entire "toolchain" means installing normally-unnecessary stuff... Most people need only the C and C++ compilers and really have no use for Ada, Fortran and etc.

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
mingw-w64-i686-headers-git mingw-w64-i686-libwinpthread-git mingw-w64-i686-tools-git mingw-w64-i686-winpthreads-git

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
mingw-w64-x86_64-headers-git mingw-w64-x86_64-libwinpthread-git mingw-w64-x86_64-tools-git mingw-w64-x86_64-winpthreads-git


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
filler56789 is offline   Reply With Quote
Old 25th December 2018, 19:59   #8  |  Link
nevcairiel
Registered Developer
 
Join Date: Mar 2010
Location: Hamburg/Germany
Posts: 10,342
Its a shame that they don't want to implement the stuff with native threading. winpthreads is kinda crappy.
Especially since someone already did all the work and made a header file with std::thread support for win32 threading model as well.

https://github.com/meganz/mingw-std-threads
__________________
LAV Filters - open source ffmpeg based media splitter and decoders

Last edited by nevcairiel; 25th December 2018 at 20:02.
nevcairiel is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:53.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.