【问题标题】:Cmake file to support C++11支持 C++11 的 Cmake 文件
【发布时间】:2017-02-24 07:06:29
【问题描述】:

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

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 上

【问题讨论】:

  • 我们需要更多信息。您使用什么命令来构建源代码?
  • mkdir build && cd build && cmake .. && make
  • cmake 版本 3.5.1
  • 然后 CMakeLists.txt 在构建的父文件夹中(因此是cmake ..)。
  • LS: CMakeCache.txt CMakeFiles cmake_install.cmake Makefile

标签: c++ c++11 makefile build cmake


【解决方案1】:

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

set(CMAKE_CXX_STANDARD 11)

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

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

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

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

【讨论】:

    猜你喜欢
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 2012-11-29
    • 2012-06-14
    • 2011-12-20
    • 1970-01-01
    相关资源
    最近更新 更多