我正在尝试在 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!