Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrono_literals is not a namespace-name

Tags:

c++

gcc

chrono

I am trying to build a program called darkstar a private FFXI server. I am trying to build this on FreeBSD 10.2 stable. I am using GCC 5.3 from ports to try to build this.

Using this make CC=gcc5 CXX=g++5 CPP="gcc5 -E" to call the correct version of GCC/G++.

This is the error code I get kicked out.

src/common/../common/../common/cbasetypes.h:336:22: error: 'chrono_literals'         is not a namespace-name
  using namespace std::chrono_literals;
                  ^
src/common/../common/../common/cbasetypes.h:336:37: error: expected namespace-name before ';' token
  using namespace std::chrono_literals;

I have checked to make sure that chrono is actually in the correct spot which it is it is at /usr/include/c++/v1/chrono.

Where the error is getting thrown this is the code that is from the line 336 in cbasetypes.h and the few lines after.

#include <chrono>

using namespace std::chrono_literals;
using server_clock = std::chrono::steady_clock;
using time_point = server_clock::time_point;
using duration = server_clock::duration;

Not sure what to do to work around this error though I figured this community would be a good place to start.

like image 626
user6031824 Avatar asked Mar 08 '16 00:03

user6031824


3 Answers

You misspelt std::literals::chrono_literals.

Remember to ensure that you're compiling the source according to C++14 (the chrono literals are not provided in C++11).

like image 94
Toby Speight Avatar answered Nov 05 '22 01:11

Toby Speight


This works for me:

using namespace std::literals::chrono_literals;

And add this in the CMakeLists.txt:

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
like image 5
dftossem Avatar answered Nov 05 '22 00:11

dftossem


#include <chrono>
 
using namespace std::chrono_literals; 

will do, but you will need at least the C++14 compilation flag.

like image 1
Jan Wilmans Avatar answered Nov 05 '22 02:11

Jan Wilmans