0

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 project generation log:

PS C:\Users\luigi\Desktop\test> cmake --version
cmake version 3.18.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).
PS C:\Users\luigi\Desktop\test> cmake -G "MinGW Makefiles" -S ./ -B build/
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/mingw-w64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/mingw-w64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
cmake_stdheaders_generator: output_include_path set to C:/Users/luigi/Desktop/test/build/mingw-std-threads-master/cmake_stdheaders_generator/cmake_stdheaders_generator
cmake_stdheaders_generator: MINGW_STDTHREADS_DIR: C:/Users/luigi/Desktop/test/mingw-std-threads-master
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/condition_variable>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/future>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/mutex>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/shared_mutex>
Matched: <C:/mingw-w64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/thread>
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/luigi/Desktop/test/build
PS C:\Users\luigi\Desktop\test>

The resulting build log with the error:

PS C:\Users\luigi\Desktop\test> cmake --build ./build -v
"C:\Program Files\CMake\bin\cmake.exe" -SC:\Users\luigi\Desktop\test -BC:\Users\luigi\Desktop\test\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\luigi\Desktop\test\build\CMakeFiles C:\Users\luigi\Desktop\test\build\\CMakeFiles\progress.marks
C:/mingw-w64/mingw64/bin/mingw32-make.exe  -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/Users/luigi/Desktop/test/build'
C:/mingw-w64/mingw64/bin/mingw32-make.exe  -f CMakeFiles\test.dir\build.make CMakeFiles/test.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/Users/luigi/Desktop/test/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\luigi\Desktop\test C:\Users\luigi\Desktop\test C:\Users\luigi\Desktop\test\build C:\Users\luigi\Desktop\test\build C:\Users\luigi\Desktop\test\build\CMakeFiles\test.dir\DependInfo.cmake --color=
Dependee "C:\Users\luigi\Desktop\test\build\CMakeFiles\test.dir\DependInfo.cmake" is newer than depender "C:/Users/luigi/Desktop/test/build/CMakeFiles/test.dir/depend.internal".
Dependee "C:/Users/luigi/Desktop/test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/Users/luigi/Desktop/test/build/CMakeFiles/test.dir/depend.internal".
Scanning dependencies of target test
mingw32-make.exe[2]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
C:/mingw-w64/mingw64/bin/mingw32-make.exe  -f CMakeFiles\test.dir\build.make CMakeFiles/test.dir/build
mingw32-make.exe[2]: Entering directory 'C:/Users/luigi/Desktop/test/build'
[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.obj
C:\mingw-w64\mingw64\bin\g++.exe -DMINGW_STDTHREADS_GENERATED_STDHEADERS @CMakeFiles/test.dir/includes_CXX.rsp -std=gnu++14 -o CMakeFiles\test.dir\test.cpp.obj -c C:\Users\luigi\Desktop\test\test.cpp
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:\Users\luigi\Desktop\test\test.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]: *** [CMakeFiles\test.dir\build.make:82: CMakeFiles/test.dir/test.cpp.obj] Error 1
mingw32-make.exe[2]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:132: CMakeFiles/test.dir/all] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/luigi/Desktop/test/build'
mingw32-make.exe: *** [Makefile:148: all] Error 2
PS C:\Users\luigi\Desktop\test>

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!

  • Can you please add the `-v` option to the cmake call, and show us what exactly were the commands and error messages issued befor these error messages you show? – πάντα ῥεῖ Oct 18 '20 at 19:35
  • @πάνταῥεῖ I added the project generation log, with CMake's version displayed. – rapfamily4 Oct 19 '20 at 08:54
  • `I added the project generation log` Please show the _verbose_ build log. `cmake --build ./build -v` – KamilCuk Oct 19 '20 at 09:00
  • 1
    @KamilCuk I just added the verbose option. Thanks. – rapfamily4 Oct 19 '20 at 09:39
  • @rapfamily4 OK. Well, the [`std::shared_lock`](https://en.cppreference.com/w/cpp/thread/shared_lock) type was introduced with c++14 (as you can see in the documentation link). g++ is called with the `-std=g++14` compiler flag correctly it seems. Ensure that the GCC compiler versionj you have supports `std::shared_lock`. Maybe update your MinGW / GCC version to the latest standard, that's the best advice I can give here. – πάντα ῥεῖ Oct 19 '20 at 10:17
  • What's the exact gcc version you use? In particular the thread model is important, because the win32 thread model doesn't have [thread support](https://stackoverflow.com/a/30390278/1983398). – ssbssa Oct 19 '20 at 10:35
  • @ssbssa I currently have GCC and G++ v.8.1.0 (as the generation log displays). These are the latest versions of the compilers in MinGW-_w64_. The thread model is actually win32... What do you suggest? – rapfamily4 Oct 19 '20 at 13:34
  • @πάνταῥεῖ I currently have the most updated MinGW-w64 available on Windows right now. – rapfamily4 Oct 19 '20 at 13:51

0 Answers0