Cmake文件以支持c++ 11

Cmake file to support C++11

本文关键字:c++ 支持 文件 Cmake      更新时间:2023-10-16

我需要构建和制作源代码,但是出现这个错误:

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.

我在其他主题中看到,这很容易通过将CMakeLists.txt中的标志更改为'-std=c++11'来修复,但在构建目录中没有CMakeLists.txt。

有人能帮帮我吗?

——OBS:我是Ubuntu 16.04

在CMake项目中启用c++11的最干净的方法是在主CMakeLists.txt中设置变量CMAKE_CXX_STANDARD。

set(CMAKE_CXX_STANDARD 11)

您可能还需要将CMAKE_CXX_EXTENSIONS设置为off以使用-std=c++11而不是GCC扩展的默认-std=gnu++11。

变量和相关属性记录在这里:

https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html变量:CMAKE_CXX_STANDARD

https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_EXTENSIONS.html