CMake error at CMakeLists.txt:117(message): The C++ compiler does not support C++11(e.g.std:unique_ptr)

Ubuntu 18.04 LTS
Cmake 3.19.4
Build failure - any help appreciated!
Error log -
Determining if compiler supports C++ make_unique failed with the following output:
Change Dir: /mnt/c/Users/john/pico/cmake-3.19.4/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_a7148/fast && make: Warning: File ‘Makefile’ has modification time 0.99 s in the future
make -f CMakeFiles/cmTC_a7148.dir/build.make CMakeFiles/cmTC_a7148.dir/build
make[1]: Entering directory ‘/mnt/c/Users/john/pico/cmake-3.19.4/CMakeFiles/CMakeTmp’
make[1]: Warning: File ‘CMakeFiles/cmTC_a7148.dir/flags.make’ has modification time 0.95 s in the future
Building CXX object CMakeFiles/cmTC_a7148.dir/cm_cxx_make_unique.cxx.o
/usr/bin/g++ -std=gnu++11 -o CMakeFiles/cmTC_a7148.dir/cm_cxx_make_unique.cxx.o -c /mnt/c/Users/john/pico/cmake-3.19.4/Source/Checks/cm_cxx_make_unique.cxx
/mnt/c/Users/john/pico/cmake-3.19.4/Source/Checks/cm_cxx_make_unique.cxx: In function ‘int main()’:
/mnt/c/Users/john/pico/cmake-3.19.4/Source/Checks/cm_cxx_make_unique.cxx:4:33: error: ‘make_unique’ is not a member of ‘std’
std::unique_ptr u = std::make_unique(0);
/mnt/c/Users/john/pico/cmake-3.19.4/Source/Checks/cm_cxx_make_unique.cxx:4:33: note: suggested alternative: ‘make_unsigned’
std::unique_ptr u = std::make_unique(0);
/mnt/c/Users/john/pico/cmake-3.19.4/Source/Checks/cm_cxx_make_unique.cxx:4:45: error: expected primary-expression before ‘int’
std::unique_ptr u = std::make_unique(0);
CMakeFiles/cmTC_a7148.dir/build.make:84: recipe for target ‘CMakeFiles/cmTC_a7148.dir/cm_cxx_make_unique.cxx.o’ failed
make[1]: *** [CMakeFiles/cmTC_a7148.dir/cm_cxx_make_unique.cxx.o] Error 1
make[1]: Leaving directory ‘/mnt/c/Users/john/pico/cmake-3.19.4/CMakeFiles/CMakeTmp’
Makefile:140: recipe for target ‘cmTC_a7148/fast’ failed
make: *** [cmTC_a7148/fast] Error 2

Determining if compiler supports C++ unique_ptr failed with the following output:
Change Dir: /mnt/c/Users/john/pico/cmake-3.19.4/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make cmTC_b23dd/fast && make: Warning: File ‘Makefile’ has modification time 0.97 s in the future
make -f CMakeFiles/cmTC_b23dd.dir/build.make CMakeFiles/cmTC_b23dd.dir/build
make[1]: Entering directory ‘/mnt/c/Users/john/pico/cmake-3.19.4/CMakeFiles/CMakeTmp’
make[1]: Warning: File ‘CMakeFiles/cmTC_b23dd.dir/flags.make’ has modification time 0.93 s in the future
Building CXX object CMakeFiles/cmTC_b23dd.dir/cm_cxx_unique_ptr.cxx.o
/usr/bin/g++ -std=gnu++11 -o CMakeFiles/cmTC_b23dd.dir/cm_cxx_unique_ptr.cxx.o -c /mnt/c/Users/john/pico/cmake-3.19.4/Source/Checks/cm_cxx_unique_ptr.cxx
Linking CXX executable cmTC_b23dd
/mnt/c/Users/john/pico/cmake-3.19.4/Bootstrap.cmk/cmake -E cmake_link_script CMakeFiles/cmTC_b23dd.dir/link.txt --verbose=1
/usr/bin/g++ CMakeFiles/cmTC_b23dd.dir/cm_cxx_unique_ptr.cxx.o -o cmTC_b23dd
make[1]: warning: Clock skew detected. Your build may be incomplete.
make[1]: Leaving directory ‘/mnt/c/Users/john/pico/cmake-3.19.4/CMakeFiles/CMakeTmp’
make: warning: Clock skew detected. Your build may be incomplete.

And the make warnings about your clock do not worry you?

I suspect there is some timestamp translation errors in WINE or another setup here. Is this WINE or just a mount of a Windows partition into Linux? This would be the first thing I’d look into.

This is using Ubuntu under windows, using WSL.
I am new to Cmake, I’m trying to follow the sequence of instructions in this video - - so that I can program a Raspberry Pi Pico in C.
I noticed the timestamp error, but don’t know what is causing it or how to correct it. Any suggestions welcome.

Are you using a Fat32 partition?

Problem solved - switched to WSL version 1 instead of version 2.
Cmake then ran without errors.
Thanks for the helpful suggestions.

That doesn’t sound like a solution. It seems that the filesystem translation layer is losing information on partitions mounted into Linux from Windows. There’s not much CMake can do about this since it is a system configuration problem.

The research I’ve managed to do suggests that WSL v2 has some timestamp issues that aren’t present in WSL v1, but I don’t know the details - I just changed from WSL V2 to WSL V1, cleared my Cmake files, unpacked them again and ran the build, which this time completed without errors.

The std::make_unique to initialize unique_ptr is available from C++14 in advance. Either you initialize the std::unique_ptr with the C++11 way or update the CMake to use C++14.

1 Like

There were several more complains about this bug.

I promptly found 1) a thread at stackoverflow where they blame cross build [ stackoverflow. com/questions/55772725/the-c-compiler-does-not-support-c11-e-g-stdunique-ptr-building-openwrt ], 2) a post in a blog where they blame mount directory and c flags [ thelinuxcluster. com/2021/10/01/the-c-compiler-does-not-support-c11-during-bootstrap-for-cmake/ ], 3) a gitlab thread where they blame distcc [ gitlab.kitware .com/cmake/cmake/-/issues/22573 ], 4) a discussion in the official CMake forum where they blame windows for it [ discourse.cmake .org/t/cmake-error-at-cmakelists-txt-117-message-the-c-compiler-does-not-support-c-11-e-g-std-unique-ptr/3774 ] and last but least a gentoo bug where they blame enviroment variables too [ bugs.gentoo .org/691544 ].

Each of them finds a different work around: moving the build to another directory, remounting a storage point, changing c flags to “-O3”, switching windows subsystem for linux implementation, force usage of C++14, etc.

I personally bypassed this check as I was sure my compiler supported C++11 features like ‘std:unique_ptr’ despite Cmake complains. It’s not a definite patch, but as it’s been a standard since late 2000’s, very few people should not have C++11 support and those who don’t must be very well aware of what they’re doing.

Here’s the patch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9944ea4c..195fd842 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
-  # include special compile flags for some compilers
-  include(CompileFlags.cmake)
-  # check for available C++ features
-  include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
-    message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
-  endif()
 # Inform STL library header wrappers whether to use system versions.