C 11:现代g上的“put_time不是std的成员”
我在新编译器上遇到了一个老问题.尝试使用std :: chrono打印当前时间时收到以下错误:
src/main.cpp:51:30: error: ‘put_time’ is not a member of ‘std’
std::cout << std::put_time(std::localtime(&time), "%c") << "\n\n";
^~~
违规片段没什么特别之处:
#include <chrono>
...
auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::cout << std::put_time(std::localtime(&time), "%c") << "\n\n";
这看起来非常像GCC 4.x系列中返回的错误,如同所引用的那样:
> std::put_time implementation status in GCC?> Why does std::put_time not compile using multiple compilers?> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54354
这个理论唯一的问题是我的GCC是现代的:
$g++ --version
g++ (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我还检查了我的应用程序是否链接到相应的库:
$ldd build/myapp
...
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fde97e7b000)
libc.so.6 => /lib64/libc.so.6 (0x00007fde97595000)
最后,我的编译标志中没有任何异国情调:
g++ -g -Wall -Werror -std=c++11 -Wno-sign-compare src/main.cpp -c -o obj/main.o
我能想到检查的一切都表明这应该有效.那么,总之,给出了什么?