date
date copied to clipboard
Cannot use make_zoned
I wrote this code according to the examples in documentation but I didn't work
I tried configure the library using vcpkg and the fetchcontent in cmake, but both come out with the same result.
My environment: Operating system: Windows 11 Pro for workstation Compiler: Visual Studio Community 2019 Release - AMD64 CPU: AMD Ryzen 5900HS Editor / IDE: Tried both on VS2019 and VSCode
This is the code
#include <iostream>
#include <date/tz.h>
using namespace std;
using namespace std::chrono_literals;
using namespace date;
int main()
{
auto zt = make_zoned("Asia/Shanghai", local_days{apr/30/2004} + 8h);
return 0;
}
This is the build message
[main] Building folder: date_test DateTest
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/Asiimoviet/Repositories/date_test/build --config Debug --target DateTest -j 18 --
[build] Microsoft (R) Build Engine version 16.11.1+3e40a09f8 for .NET Framework
[build] Copyright (C) Microsoft Corporation. All rights reserved.
[build]
[build] main.cpp
[build] main.obj : error LNK2019: unresolved external symbol "class date::time_zone const * __cdecl date::locate_zone(class std::basic_string_view<char,struct std::char_traits<char> >)" (?locate_zone@date@@YAPEBVtime_zone@1@V?$basic_string_view@DU?$char_traits@D@std@@@std@@@Z) referenced in function "public: static class date::time_zone const * __cdecl date::zoned_traits<class date::time_zone const *>::locate_zone(class std::basic_string_view<char,struct std::char_traits<char> >)" (?locate_zone@?$zoned_traits@PEBVtime_zone@date@@@date@@SAPEBVtime_zone@2@V?$basic_string_view@DU?$char_traits@D@std@@@std@@@Z) [C:\Users\Asiimoviet\Repositories\date_test\build\DateTest.vcxproj]
[build] main.obj : error LNK2019: unresolved external symbol "private: struct date::local_info __cdecl date::time_zone::get_info_impl(class std::chrono::time_point<struct date::local_t,class std::chrono::duration<__int64,struct std::ratio<1,1> > >)const " (?get_info_impl@time_zone@date@@AEBA?AUlocal_info@2@V?$time_point@Ulocal_t@date@@V?$duration@_JU?$ratio@$00$00@std@@@chrono@std@@@chrono@std@@@Z) referenced in function "public: struct date::local_info __cdecl date::time_zone::get_info<class std::chrono::duration<__int64,struct std::ratio<1,1> > >(class std::chrono::time_point<struct date::local_t,class std::chrono::duration<__int64,struct std::ratio<1,1> > >)const " (??$get_info@V?$duration@_JU?$ratio@$00$00@std@@@chrono@std@@@time_zone@date@@QEBA?AUlocal_info@1@V?$time_point@Ulocal_t@date@@V?$duration@_JU?$ratio@$00$00@std@@@chrono@std@@@chrono@std@@@Z) [C:\Users\Asiimoviet\Repositories\date_test\build\DateTest.vcxproj]
[build] C:\Users\Asiimoviet\Repositories\date_test\build\Debug\DateTest.exe : fatal error LNK1120: 2 unresolved externals [C:\Users\Asiimoviet\Repositories\date_test\build\DateTest.vcxproj]
[build] Build finished with exit code 1
In case you'll need it, this is the cmakelists.txt
cmake_minimum_required(VERSION 3.0)
project(DateTest VERSION 1.0)
include(FetchContent)
FetchContent_Declare(date_src
GIT_REPOSITORY https://github.com/HowardHinnant/date.git
GIT_TAG v3.0.1
)
FetchContent_MakeAvailable(date_src)
add_executable(DateTest main.cpp)
target_link_libraries(DateTest PRIVATE date::date)
I tried your example using a Debian system and faced the same problems. You might want to change the target date::date
to date::date-tz
.
cmake_minimum_required(VERSION 3.14)
project(DateTest VERSION 1.0
LANGUAGES CXX)
set(USE_SYSTEM_TZ_DB ON CACHE INTERNAL "")
set(BUILD_TZ_LIB ON CACHE INTERNAL "")
include(FetchContent)
FetchContent_Declare(date_src
GIT_REPOSITORY https://github.com/HowardHinnant/date.git
GIT_TAG v3.0.1
)
FetchContent_MakeAvailable(date_src)
add_executable(DateTest main.cpp)
target_link_libraries(DateTest PRIVATE date::date-tz
)
I also set the options to avoid curl dependency and build the library.
Hope this helps to get into the right direction.