Build issues with shared_mutex and MinGW-w64

  c++, cmake, g++, mingw-w64, mutex

I’m currently working on a C++14 project, using MinGW-w64 and a CMake configuration (MinGW Makefile generator). I’m having a hard time building it due to compatibility issues with the shared_mutex library. To circumnavigate such problems, I’m using a custom header-only library called mingw-std-threads. After following all the instructions of the library’s mark-down file, I still have errors with shared_mutex.

Here’s a minimal reproducible example of the error I am getting. Source file:

#include <shared_mutex>

int main()
{
     return 0;
}

The CMake configuration for the test:

# CMake 3.9 or newer
cmake_minimum_required(VERSION 3.9)

# project name, version and description
project(test)

# C++14 or higher
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# library target
add_executable(test test.cpp)

# include directories
target_include_directories(test PRIVATE .)

#MinGW threads
option(MINGW_STDTHREADS_GENERATE_STDHEADERS "" ON)
add_subdirectory(./mingw-std-threads-master)
target_link_libraries(test PRIVATE mingw_stdthreads)

# defining install rules
include(GNUInstallDirs)
install(TARGETS test
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

The resulting error log:

PS C:UsersluigiDesktoptest> cmake --build ./build
[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.obj
In file included from C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.condition_variable.h:53,
                 from C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator/condition_variable:10,
                 from C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/shared_mutex:37,
                 from C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator/shared_mutex:9,
                 from C:UsersluigiDesktoptesttest.cpp:1:
C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.shared_mutex.h:306:12: error: 'std::shared_lock' has not been declared
 using std::shared_lock;
            ^~~~~~~~~~~
C:/Users/luigi/Desktop/test/mingw-std-threads-master/mingw.shared_mutex.h:492:24: error: 'mingw_stdthread::shared_lock' has not been declared
 using mingw_stdthread::shared_lock;
                        ^~~~~~~~~~~
mingw32-make.exe[2]: *** [CMakeFilestest.dirbuild.make:82: CMakeFiles/test.dir/test.cpp.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:132: CMakeFiles/test.dir/all] Error 2
mingw32-make.exe: *** [Makefile:148: all] Error 2
PS C:UsersluigiDesktoptest>

These are the versions of the tools I’m using:

  • Windows 10 Pro x64
  • MinGW-w64 8.1.0
  • CMake 3.18.3 (using 3.9 for the configuration)
  • mingw-std-threads 1.0.0

Thanks for helping!

Source: Windows Questions C++

LEAVE A COMMENT