如何在 CLion 中启用 C++11?

2023-08-28C/C++开发问题
17

本文介绍了如何在 CLion 中启用 C++11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试在 CLion 中运行 C++11 代码,但它不起作用.它说:

I'm trying to run C++11 code in CLion but it doesn't work. It says:

...
    /projects/CLion/untitled/main.cpp:7:1: note: C++11 ‘constexpr’ only available with -std=c++11 or -std=gnu++11
...

我尝试将 CMAKE_C_FLAGS 设置为 -std=c++11-std=gnu++11 但我仍然有同样的问题.常规 C++ 代码编译良好.

I tried to set CMAKE_C_FLAGS to -std=c++11 or -std=gnu++11 but I still have the same problem. Regular C++ code compiles fine.

我必须在 CLion 的 CMake 窗口中设置什么标志来编译我的 C++11 代码?

What flag do I have to set in CLion's CMake window to compile my C++11 code?

推荐答案

我尝试设置 CMAKE_C_FLAGS

I tried to set CMAKE_C_FLAGS

根据文档,CMAKE_C_FLAGS为所有构建类型设置 C 语言标志.对于 C++,您需要使用 CMAKE_CXX_FLAGS 代替:

According to the documentation the CMAKE_C_FLAGS set C language flags for all build types. For C++ you need use CMAKE_CXX_FLAGS instead:

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

这篇关于如何在 CLion 中启用 C++11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6