mariusbancila / croncpp

A C++11/14/17 header-only cross-platform library for handling CRON expressions
MIT License
236 stars 68 forks source link

g++ 4.8.5 build failed with no std::put_time() & std::get_time() #15

Closed laoshanxi closed 3 years ago

laoshanxi commented 3 years ago

I am trying to use this lib in app-mesh, faced below compile error:

20:55:08 In file included from /opt/jenkins_data/workspace/appmesh/src/daemon/application/ApplicationCron.cpp:5:0:
20:55:08 /opt/jenkins_data/workspace/appmesh/src/daemon/application/../../common/croncpp.h: In function 'tm cron::utils::to_tm(const string&)':
20:55:08 /opt/jenkins_data/workspace/appmesh/src/daemon/application/../../common/croncpp.h:265:17: error: 'get_time' is not a member of 'std'
20:55:08           str >> std::get_time(&result, "%Y-%m-%d %H:%M:%S");
20:55:08                  ^
20:55:08 /opt/jenkins_data/workspace/appmesh/src/daemon/application/../../common/croncpp.h: In function 'std::string cron::utils::to_string(const tm&)':
20:55:08 /opt/jenkins_data/workspace/appmesh/src/daemon/application/../../common/croncpp.h:277:17: error: 'put_time' is not a member of 'std'
20:55:08           str << std::put_time(&tm, "%Y-%m-%d %H:%M:%S");
20:55:08                  ^
20:55:09 make[2]: *** [src/daemon/application/CMakeFiles/application.dir/ApplicationCron.cpp.o] Error 1
20:55:09 make[1]: *** [src/daemon/application/CMakeFiles/application.dir/all] Error 2
mariusbancila commented 3 years ago

std::put_time() and std::get_time() are part of C++11 and defined in <iomanip>. This header is included in the cron header:

#include <vector>
#include <string>
#include <sstream>
#include <bitset>
#include <cctype>
#include <ctime>
#include <iomanip>
#include <algorithm>

As far as I can figure out, support for this was added only in version 5.1.0. Proof: https://godbolt.org/z/a48eGnbGc

You'll need to use a newer version of the compiler.