error: ‘chrono’ in namespace ‘std’ does not name a type
Asked Answered
L

3

5

Any idea what does this message mean? I am using gcc 4.9 to compile squangle.

In file included from /home/ubuntu/Devel/hhvm/third-party/squangle/squangle/mysql_client/Row.cpp:10:0:
/home/ubuntu/Devel/hhvm/third-party/squangle/src/squangle/mysql_client/Row.h:171:6: error: ‘chrono’ in namespace ‘std’ does not name a type
 std::chrono::system_clock::time_point parseDateTime(StringPiece datetime,
      ^
/home/ubuntu/Devel/hhvm/third-party/squangle/src/squangle/mysql_client/Row.h:174:6: error: ‘chrono’ in namespace ‘std’ does not name a type
 std::chrono::microseconds parseTimeOnly(StringPiece mysql_time,
      ^
/home/ubuntu/Devel/hhvm/third-party/squangle/src/squangle/mysql_client/Row.h:354:6: error: ‘chrono’ in namespace ‘std’ does not name a type
 std::chrono::system_clock::time_point RowBlock::getField(
      ^
/home/ubuntu/Devel/hhvm/third-party/squangle/src/squangle/mysql_client/Row.h:358:6: error: ‘chrono’ in namespace ‘std’ does not name a type
 std::chrono::microseconds RowBlock::getField(size_t row,
      ^
/home/ubuntu/Devel/hhvm/third-party/squangle/squangle/mysql_client/Row.cpp: In member function ‘T facebook::common::mysql_client::RowBlock::getField(size_t, size_t) const [with T = std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1l, 1000000000l> > >; size_t = long unsigned int]’:

Here is part of the code:

std::chrono::system_clock::time_point parseDateTime(StringPiece datetime,
                                                    enum_field_types date_type);

std::chrono::microseconds parseTimeOnly(StringPiece mysql_time,
                                        enum_field_types field_type);

CXX_FLAGS

CXX_FLAGS =  -Wall -std=gnu++11 -ffunction-sections -fno-gcse -fno-omit-frame-pointer -Woverloaded-virtual -Wno-deprecated -Wno-strict-aliasing -Wno-write-strings -Wno-invalid-offsetof -fno-operator-names -Wno-error=array-bounds -Wno-error=switch -Werror=format-security -Wno-unused-result -Wno-sign-compare -Wno-attributes -Wno-maybe-uninitialized -Wno-unused-local-typedefs -fno-canonical-system-headers -Wno-deprecated-declarations -Wno-unused-function  -ftrack-macro-expansion=0 -fno-builtin-memcmp -fno-delete-null-pointer-checks  -Wno-unused-variable -O3 -DNDEBUG -fno-gcse  --param max-inline-insns-auto=100 --param early-inlining-insns=200 --param max-early-inliner-iterations=50 -I/usr/include/powerpc64le-linux-gnu -I/home/ubuntu/Devel/hhvm/third-party/re2/src -I/home/ubuntu/Devel/hhvm/third-party/squangle/src -I/home/ubuntu/Devel/hhvm/third-party/webscalesqlclient/src/include -I/usr/include/libxml2 -I/usr/include/double-conversion -I/usr/include/security -I/home/ubuntu/Devel/hhvm/hphp -I/home/ubuntu/Devel/hhvm/third-party/libzip -I/home/ubuntu/Devel/hhvm/third-party/pcre -I/home/ubuntu/Devel/hhvm/third-party/fastlz -I/home/ubuntu/Devel/hhvm/third-party/timelib -I/home/ubuntu/Devel/hhvm/third-party/libafdt/src -I/home/ubuntu/Devel/hhvm/third-party/libmbfl -I/home/ubuntu/Devel/hhvm/third-party/libmbfl/mbfl -I/home/ubuntu/Devel/hhvm/third-party/libmbfl/filter -I/home/ubuntu/Devel/hhvm/third-party/mcrouter -I/home/ubuntu/Devel/hhvm/third-party/folly -I/home/ubuntu/Devel/hhvm/third-party/thrift -I/home/ubuntu/Devel/hhvm/third-party -I/home/ubuntu/Devel/hhvm -I/home/ubuntu/Devel/hhvm/third-party/squangle

Compiler line:

g++
-DENABLE_FASTCGI=1
-DENABLE_ZEND_COMPAT=1
-DFOLLY_HAVE_CLOCK_GETTIME=1
-DFOLLY_HAVE_FEATURES_H=1
-DFOLLY_HAVE_PTHREAD_ATFORK=1
-DFOLLY_HAVE_PTHREAD_SPINLOCK_T=1
-DFOLLY_HAVE_WEAK_SYMBOLS=1
-DFOLLY_NO_CONFIG=1
-DHAVE_BOOST1_49
-DHAVE_CURL_MULTI_WAIT
-DHAVE_ELF_GETSHDRSTRNDX
-DHAVE_FEATURES_H=1
-DHAVE_LIBDL
-DHHVM
-DHHVM_DYNAMIC_EXTENSION_DIR="/usr/local/lib/hhvm/extensions"
-DHPHP_OSS=1
-DLIBDWARF_USE_INIT_C
-DNDEBUG
-DNO_LIB_GFLAGS
-DNO_TCMALLOC=1
-DPACKAGE=hhvm
-DPACKAGE_VERSION=Release
-DPHP_MYSQL_UNIX_SOCK_ADDR="/var/run/mysqld/mysqld.sock"
-DRELEASE=1
-DTHRIFT_MUTEX_EMULATE_PTHREAD_TIMEDLOCK
-DUSE_EDITLINE
-DUSE_JEMALLOC=1
-D_GNU_SOURCE
-D_PTHREADS=1
-D_REENTRANT=1
-D__STDC_FORMAT_MACROS
-Wall
-std=gnu++11
-ffunction-sections
-fno-gcse
-fno-omit-frame-pointer
-Woverloaded-virtual
-Wno-deprecated
-Wno-strict-aliasing
-Wno-write-strings
-Wno-invalid-offsetof
-fno-operator-names
-Wno-error=array-bounds
-Wno-error=switch
-Werror=format-security
-Wno-unused-result
-Wno-sign-compare
-Wno-attributes
-Wno-maybe-uninitialized
-Wno-unused-local-typedefs
-fno-canonical-system-headers
-Wno-deprecated-declarations
-Wno-unused-function
-ftrack-macro-expansion=0
-fno-builtin-memcmp
-fno-delete-null-pointer-checks
-Wno-unused-variable
-O3
-DNDEBUG
-fno-gcse
--param
max-inline-insns-auto=100
--param
early-inlining-insns=200
--param
max-early-inliner-iterations=50
-I/usr/include/powerpc64le-linux-gnu
-I/home/ubuntu/Devel/hhvm/third-party/re2/src
-I/home/ubuntu/Devel/hhvm/third-party/squangle/src
-I/home/ubuntu/Devel/hhvm/third-party/webscalesqlclient/src/include
-I/usr/include/libxml2
-I/usr/include/double-conversion
-I/usr/include/security
-I/home/ubuntu/Devel/hhvm/hphp
-I/home/ubuntu/Devel/hhvm/third-party/libzip
-I/home/ubuntu/Devel/hhvm/third-party/pcre
-I/home/ubuntu/Devel/hhvm/third-party/fastlz
-I/home/ubuntu/Devel/hhvm/third-party/timelib
-I/home/ubuntu/Devel/hhvm/third-party/libafdt/src
-I/home/ubuntu/Devel/hhvm/third-party/libmbfl
-I/home/ubuntu/Devel/hhvm/third-party/libmbfl/mbfl
-I/home/ubuntu/Devel/hhvm/third-party/libmbfl/filter
-I/home/ubuntu/Devel/hhvm/third-party/mcrouter
-I/home/ubuntu/Devel/hhvm/third-party/folly
-I/home/ubuntu/Devel/hhvm/third-party/thrift
-I/home/ubuntu/Devel/hhvm/third-party
-I/home/ubuntu/Devel/hhvm
-I/home/ubuntu/Devel/hhvm/third-party/squangle
-o
CMakeFiles/squangle.dir/squangle/mysql_client/Row.cpp.o
-c
/home/ubuntu/Devel/hhvm/third-party/squangle/squangle/mysql_client/Row.cpp
Laritalariviere answered 21/5, 2015 at 13:0 Comment(8)
did you include the right headers (e.g. <chrono>)? does your compiler supports C++11?Southeastwardly
@DavidHaim: As much as I wish it were so, there's not really any such thing as a compiler "supporting C++11"; compilers support and do not support various individual features from C++11, C++14, C++17...Galcha
this is what I like about stack overflow, arguing about dictionary-resolution definitions ...Southeastwardly
How are you building squangle? If you're doing it as part of the HHVM build, we make sure to pass the right C++11 flags. Can you update your question to include the configure and make commands you're using? Also, what OS are you using?Scaliger
Are you sure CXX_FLAGS is the right variable? The conventional make variable is CXXFLAGS. Could something else be adding -std=c++98 or similar after your CXX_FLAGS? Look at the complete command-line, not just what you think you're using.Wozniak
Pass -H to g++ to ask it to print every included header file.Stockbreeder
And if you're using GCC then including <chrono> without enabling C++11 support will give an error, are you looking at the very first error you get? Did you only show us some of the errors?Wozniak
@DavidHaim: Except the distinction may very well be the key to this problem. Precision is important in our field.Galcha
G
5

It means squangle doesn't include the proper headers (it does), or your compiler doesn't support std::chrono (it does), or you are not compiling as C++11, using the -std=c++11 switch.

Galcha answered 21/5, 2015 at 13:2 Comment(9)
Interesting. I am using -std=gnu++11. Shouldn't it be the same?Daggna
@BrenoLeitão: They're not the same, but -std=gnu++11 should be -std=c++11 plus GNU extensions so should cover that requirement. As Jonathan said, are you sure you should be writing to CXX_FLAGS, not CXXFLAGS? Remove the makefile from the equation by testing with an actual g++ command-line invocation. Divide and conquer.Galcha
Yes, I confirmed it. Here is the exact line that the compiler is being called: gist.github.com/leitao/616c25548f0382a68ccfDaggna
@BrenoLeitão: Please use -v to prove that you are invoking GCC 4.9.Galcha
@BrenoLeitão: I'm out of ideas.Galcha
I am wondering if I a missing something on my toolchain, but it seem a small example works fine. Anyway, thanks!Daggna
@BrenoLeitão: Hmm, what small example? Then simply compare the differences between that example and the one in your question and you have the answer! (This is precisely why we ask you to compose a minimal testcase before posting!)Galcha
@LightnessRacesinOrbit why is -std=c++11 switch necessary ? I have the exact same error with -std=c++14 but it goes away with -std=c++11, but I need to have c++14 for dependencies in my project.Inculcate
@AbhishekKedia: -std=c++14 should work too. It just has to be C++11 or newer. It sounds like you forgot to #include <chrono> and just got [un]lucky with your toolchain's C++11 implementation happening to include it transitively — and for some reason its C++14 implementation does not.Galcha
L
3

Adding using namespace std::chrono; in addition to #include <chrono> solved my problem.

Licensee answered 16/1, 2020 at 15:22 Comment(0)
D
2

try to use -std=c++20 if the parameter of -std=c++11/17 not works since some of the features in std::chrono release from C++20.

the version of my g++ is 12.1.0 and only -std=c++20 works.

Dioxide answered 22/11, 2022 at 13:53 Comment(1)
None of the errors from OP's post should required C++20 to work. Both microseconds and system_clock are from C++11. In fact, using -std=c++20 is guaranteed to not work for OP since he's using an older version of GCC, that does not support the c++20 flag.Bratcher

© 2022 - 2024 — McMap. All rights reserved.