16

I have just installed Qt Creator and am using C++11 syntax.

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".

My CMakeLists.txt contains:

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

A T
  • 13,008
  • 21
  • 97
  • 158

1 Answers1

36

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})
László Papp
  • 51,870
  • 39
  • 111
  • 135
  • Ah, so CMAKE rather than GMAKE. – A T Dec 29 '13 at 14:31
  • @AT: you mean `QMAKE`, not `GMAKE`. You are the second person today making this typo. :) – László Papp Dec 29 '13 at 14:32
  • 1
    @AT: you need to rerun cmake. – László Papp Dec 29 '13 at 14:32
  • Ran `cmake` via command line, then `make`; and still got the errors. – A T Dec 29 '13 at 14:35
  • @AT: that is about impossible. ;) Paste a main.cpp reproducing the issue. Also, check my project link above. How exactly do you rerun cmake? – László Papp Dec 29 '13 at 14:35
  • Old version of gcc that does not support c++11? Would that ignore the parameter or error out? – drescherjm Dec 29 '13 at 14:38
  • @drescherjm: he has 4.8 based on the question which is good enough for tuple, et al. It is the latest major variant. `#if __cplusplus < 201103L` satisfies for the OP for some reason. – László Papp Dec 29 '13 at 14:38
  • @AT: try to pass -std=c++0x. Does that work? Also, try "-std=gnu++11" for a moment. Try also `set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")` – László Papp Dec 29 '13 at 14:39
  • 7
    Please try also `add_definitions("-std=c++11")`. – László Papp Dec 29 '13 at 14:44
  • @AT: what does gcc --version return? Are you sure you do not have some obsolete version in the path? Have you tried each hint I gave you? – László Papp Dec 29 '13 at 14:47
  • Your `set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")` one did the trick. I have edited your question with that solution + code example to show that it works. Accept my edit and I'll accept + up-vote your answer :) – A T Dec 29 '13 at 14:52
  • Oh, I tried to edit it with the answer, you didn't accept my edits? – A T Dec 29 '13 at 15:05
  • @AT: someone else rejected it, I am afraid, http://stackoverflow.com/review/suggested-edits/3684662. I already exceeded my daily review quota about 10 hours ago, or so. – László Papp Dec 29 '13 at 15:07
  • @AT I would accept this answer as the answer to the question instead of putting the answer in the question itself. – drescherjm Dec 29 '13 at 15:18
  • 1
    @drescherjm: I think AT just wanted to edit my answer, but it unfortunately got rejected. There is no problem though as the gist is pointed out, and the issue is resolved now. – László Papp Dec 29 '13 at 15:20
  • @LaszloPapp: Ahh, I see you reached your quota. No worries, I have committed the edit again for your review. – A T Dec 30 '13 at 05:17
  • accoriding to: http://clang.llvm.org/cxx_status.html "You can use Clang in C++14 mode with the -std=c++14 option (use -std=c++1y in Clang 3.4 and earlier)." – squid Jun 11 '15 at 02:28