<chrono> C++11 namespace issues

Hi,

I am trying to use <chrono> in ubuntu 14.04 with g++/gcc 4.8.2 and I cannot see the std::chrono namespace. My development enviroment is eclipse luna, using cmake 2.8.2 (all from repository in 14.04).

I can include the header, which it sees in /usr/include/c++/4.8/, but I get build errors saying it cannot find std::chrono. I am trying to use the high resolution clock for a stopwatch class to calculate execution time of some code.

I saw some preprocessor macros in the chrono header but they all should be fine if I am linking against c++11. Any ideas?
You have to tell gcc what standard to use via the -std parameter.
To add to what NoXzema said, the flag you're needing is -std=c++11.
Thank you guys for your replies. I already have -std=c++11 as a linker flag. I use many lambda functions throughout in other classes within the program.

Using CMake, this is what I have:

...

# check available compiler versions
# throw error if c++11 is not available
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

# link extra link libraries
# this is global for every project...
link_libraries(-lrt -lm -lpthread)

# add additional definitions (default)
add_definitions(-Wall -W -pthread -Wno-unused -Wno-unused-parameter -Wno-sign-compare -Wno-reorder -Wno-missing-field-initializers)

...

And it indeed says it supports C++11.
Okay... Can you show me the exact line used to compile, from whatever cmake generates? Also, can you make a test case?
I was not aware that GCC supported <chrono> or <thread> yet - I thought that those headers and some others were not yet implemented?
Registered users can post here. Sign in or register to post.