0

I want to use a timer as advised in How can I measure the execution time of one thread? However, I receive the error message

In file included from /usr/include/c++/5/thread:35:0,
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^

The CMake output of

message("${CMAKE_CXX_FLAGS}" and "${CMAKE_C_FLAGS}")

is

 -std=c++11 -fPIC -Wall;and; -std=c++11

What is wrong?

katang
  • 2,474
  • 5
  • 24
  • 48
  • This is the line that raises the error: https://github.com/gcc-mirror/gcc/blob/gcc_5_3_0_release/libstdc%2B%2B-v3/include/std/thread#L34 Can you show your CMakeLists.txt? – Laurenz Aug 11 '18 at 09:05
  • Well, the problem must be outside my XMakeLists.txt. I inserted the code into one of my .h files, which was then included in a main.cpp file. When I moved literally the same code snippet (see the reference) into my .cpp file, the bug went away. – katang Aug 11 '18 at 18:31

1 Answers1

0

If you would like your project to require C++11, I suggest you do something like this:

cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
project(test)

[...]

If you are building a library, and you would like user of your library to transitively use the correct flags, you could look into https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html#requiring-language-standards

J-Christophe
  • 1,975
  • 15
  • 13