Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tzdb::locate_zone not exported on windows #850

Closed
apmorton opened this issue Oct 17, 2024 · 3 comments · Fixed by #851
Closed

tzdb::locate_zone not exported on windows #850

apmorton opened this issue Oct 17, 2024 · 3 comments · Fixed by #851

Comments

@apmorton
Copy link
Contributor

I can get the tzdb, because get_tzdb is DATE_API.

DATE_API const tzdb& get_tzdb();

If I then try to call locate_zone or current_zone on the tzdb I get link errors because they aren't exported.

@HowardHinnant
Copy link
Owner

HowardHinnant commented Oct 17, 2024

Try compiling tz.cpp with DATE_BUILD_DLL defined. This will trigger DATE_API to be defined as __declspec(dllexport): https://github.com/HowardHinnant/date/blob/master/include/date/tz.h#L122-L123.

Then when compiling the client code define DATE_USE_DLL. This will trigger DATE_API to be defined as __declspec(dllimport): https://github.com/HowardHinnant/date/blob/master/include/date/tz.h#L124-L125.

Both locate_zone and current_zone are decorated with DATE_API:

#if HAS_STRING_VIEW
DATE_API const time_zone* locate_zone(std::string_view tz_name);
#else
DATE_API const time_zone* locate_zone(const std::string& tz_name);
#endif

DATE_API const time_zone* current_zone();

https://github.com/HowardHinnant/date/blob/master/include/date/tz.h#L283-L289

Or, use std::chrono with a recent version of MSVC. This library has been part of std::chrono starting with C++20 and MSVC has been shipping it for a couple of years now. Issues such as this are far less likely to arise when using the std::lib.

https://gcc.godbolt.org/z/YxbY9jvbf

@apmorton
Copy link
Contributor Author

The free functions have DATE_API, but the tzdb member functions don't: https://github.com/HowardHinnant/date/blob/master/include/date/tz.h#L1208-L1214

@HowardHinnant
Copy link
Owner

I don't have Windows to test on. If you submit a patch that fixes your problem, I'll accept it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants