I have installed date
library using vcpkg install date:x64-windows
and I use find_package(date CONFIG REQUIRED)
to use the library in my cross-platform project. I successfully find the library (date_FOUND="1"
) in C:\Dev\vcpkg\installed\x64-windows\include\date\date.h
.
My app uses set(CMAKE_CXX_STANDARD 20)
and when I build it using Visual Studio 2022 community, the compiler complains with the following error. I am simply converting a string to a time_point
given a format.
const std::string timeString = "2020-12-18 12:30:45";
const char *fmt = "%F";
std::istringstream in(timeString);
std::chrono::time_point<std::chrono::system_clock> timeStamp;
in >> date::parse(fmt, timeStamp);
error C2672: 'date::parse': no matching overloaded function found
C:\Dev\vcpkg\installed\x64-windows\include\date/date.h(8169): note: could be 'unknown-type date::parse(const CharT *,Parsable &,std::basic_string<CharT,Traits,Alloc> &,std::chrono::minutes &)'
It was linked using:
target_link_libraries(main PRIVATE date::date date::date-tz)
I am developing a cross-platform app and therefore, I have installed date library on Linux: ./vcpkg install date:x64-linux
.
I can successfully build the same code with gcc11
, and it works on Linux.
How can I solve this issue?
This is not a direct solution, but a demonstration of a suggested workaround.
Based on Howard Hinnant's comment:
[...] drop from
date::parse
down todate::from_stream
.from_steam
offers all of theparse
functionality, but is not as nice syntax. And that may work around the issues you're seeing withdate::parse
and MSVC.
Here's a minimum demo for the problem and my workaround:
#include <iostream>
#include "date/date.h"
int main() {
std::string time = "2024-05-23";
std::chrono::system_clock::time_point tp;
std::stringstream ss(time);
//ss >> date::parse("%F", tp); //error C2672: 'date::parse': no matching overloaded function found
date::from_stream(ss, "%F", tp); //Works
std::cout << tp << "\n";
return 0;
}