如何在CMake中设置编译器标准

时间:2018-08-11 08:46:40

标签: c++11

我想按照中的建议使用计时器 How can I measure the execution time of one thread? 但是,我收到错误消息

shuffle

的CMake输出

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 \
  ^

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

怎么了?

1 个答案:

答案 0 :(得分:0)

如果您希望您的项目需要C ++ 11,建议您执行以下操作:

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

[...]

如果您正在构建库,并且希望库的用户可传递地使用正确的标志,则可以查看https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html#requiring-language-standards