将`-std = c ++ 11`传递给CMakeLists?

时间:2013-12-29 14:27:33

标签: c++ qt c++11 cmake compiler-flags

我刚刚安装了Qt Creator并使用了C ++ 11语法。

不幸的是,当我尝试构建我的项目时,我得到了:

/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 \
       ^

然后是一堆错误,例如“tuple不是std的成员”。

我的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})

编辑:显示问题的小问题https://gist.github.com/anonymous/8171073

1 个答案:

答案 0 :(得分:34)

的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

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})