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

Missing symbols when compiling for Windows with mingw-w64 #2691

Closed
rbberger opened this issue Jan 3, 2022 · 2 comments
Closed

Missing symbols when compiling for Windows with mingw-w64 #2691

rbberger opened this issue Jan 3, 2022 · 2 comments

Comments

@rbberger
Copy link
Contributor

rbberger commented Jan 3, 2022

For Windows, the fmt/chrono.h header uses _get_timezone and _get_dstbias, which seem to be only defined when using the UCRT.

Compiling with mingw-w64 causes a link error:

/usr/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: CMakeFiles/test_me.dir/objects.a(test_me.cpp.obj):test_me.cpp:(.text+0x73c): undefined reference to `__imp__get_timezone'
/usr/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: CMakeFiles/test_me.dir/objects.a(test_me.cpp.obj):test_me.cpp:(.text+0x196c): undefined reference to `__imp__get_dstbias'
collect2: error: ld returned 1 exit status

Minimal example to reproduce:

#include <fmt/chrono.h>

int main() {
  std::time_t now = std::time(nullptr);
  fmt::print("Printed on {:%a %b %d %H:%M:%S %Y}\n", fmt::localtime(now));
  return 0;
}
cmake_minimum_required(VERSION 3.10)
project(test_me)
enable_language(CXX)

add_subdirectory(fmt)

add_executable(test_me test_me.cpp)
target_link_libraries(test_me fmt)

Suggested workaround/bugfix:

diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h
index 31fee070..908999ab 100644
--- a/include/fmt/chrono.h
+++ b/include/fmt/chrono.h
@@ -1082,7 +1082,7 @@ template <typename OutputIt, typename Char> class tm_writer {
   }
   template <typename T, FMT_ENABLE_IF(!has_member_data_tm_gmtoff<T>::value)>
   void format_utc_offset_impl(const T& tm) {
-#if defined(_WIN32)
+#if defined(_WIN32) && defined(_UCRT)
 #  if FMT_USE_TZSET
     tzset_once();
 #  endif
@vitaut
Copy link
Contributor

vitaut commented Jan 3, 2022

Could you submit a PR with the proposed fix since you are in the best position to test it?

@rbberger
Copy link
Contributor Author

rbberger commented Jan 3, 2022

Sure.

rbberger added a commit to rbberger/fmt that referenced this issue Jan 3, 2022
akohlmey added a commit to akohlmey/lammps that referenced this issue Jan 3, 2022
this also reverts commit c5a7f4c
and thus results in consistent crt behavior on windows
vitaut pushed a commit that referenced this issue Jan 3, 2022
@vitaut vitaut closed this as completed Jan 3, 2022
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

No branches or pull requests

2 participants