将 `-std=c++11` 传递给 CMakeLists?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20826135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing `-std=c++11` to CMakeLists?
提问by A T
I have just installed Qt Creator and am using C++11 syntax.
我刚刚安装了 Qt Creator 并且正在使用 C++11 语法。
Unfortunately when I try to build my project I get:
不幸的是,当我尝试构建我的项目时,我得到:
/usr/include/c++/4.8/bits/c++0x_warning.h:32: error:
#error This file requires compiler and library support for the ISO C++ 2011
standard. This support is currently experimental, and must be
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
Then a bunch of errors like "tuple
not a member of std
".
然后是一堆错误,比如“tuple
不是”的成员std
。
My CMakeLists.txt contains:
我的 CMakeLists.txt 包含:
project(routing_tests)
set(QMAKE_CXXFLAGS "-std=c++11")
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
EDIT: Tiny test case showing the issue https://gist.github.com/anonymous/8171073
编辑:显示问题的小测试用例https://gist.github.com/anonymous/8171073
回答by lpapp
main.cpp
主程序
#include <iostream>
#include <tuple>
int main() {
auto foo = std::make_tuple("bar", "foo", "can");
std::cout << std::get<0>(foo) << std::get<1>(foo) << std::get<2>(foo);
}
CMakeLists.txt
CMakeLists.txt
project(tuple_tests)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# C++14: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})