ITK: GDCM fails to compile using MSVC 2019, 2022 after bump to 3.0.23

Description

GDCM fails to compile using MSVC 2019, 2022: https://open.cdash.org/index.php?project=Insight&date=2024-03-26 vs https://open.cdash.org/index.php?project=Insight&date=2024-03-27

with the errors:

T:\Dashboard\ITK\Modules\ThirdParty\GDCM\src\gdcm\Source\Common\gdcmSystem.cxx(905,3):
error C3861: 'gettimeofday': identifier not found

and

T:\Dashboard\ITK\Modules\ThirdParty\MINC\src\libminc\volume_io\Prog_utils\time.c(133,20):
error C2079: 'tv' uses undefined struct 'timeval'

Errors appeared after GDCM was bumped from 3.0.22 to 3.0.23 in 919cf42.

Not sure why this was not reported by Azure Pipelines, which uses MSVC 2019: https://github.com/InsightSoftwareConsortium/ITK/blob/master/Testing/ContinuousIntegration/AzurePipelinesWindows.yml#L83

Steps to Reproduce

Have a Windows system with MSVC 2019 or 2022 (may happen on newer versions)

  1. Clone ITK master
  2. Configure and generate
  3. Build project

Expected behavior

No compiler errors are reported.

Actual behavior

Build fails with the errors:

T:\Dashboard\ITK\Modules\ThirdParty\GDCM\src\gdcm\Source\Common\gdcmSystem.cxx(905,3):
error C3861: 'gettimeofday': identifier not found

and

T:\Dashboard\ITK\Modules\ThirdParty\MINC\src\libminc\volume_io\Prog_utils\time.c(133,20):
error C2079: 'tv' uses undefined struct 'timeval'

Reproducibility

100%

Versions

ITK master.

Environment

OS: Windows Compiler: MSVC 2019, 2022

Additional Information

File at issue at GDCM 3.0.23: https://github.com/malaterre/GDCM/blob/v3.0.23/Source/Common/gdcmSystem.cxx

File at issue at GDCM 3.0.22: https://github.com/malaterre/GDCM/blob/v3.0.22/Source/Common/gdcmSystem.cxx

They are exactly the same, so maybe it is this block, where gettimeofday is defined, that is not being compiled: https://github.com/malaterre/GDCM/blob/master/Source/Common/gdcmSystem.cxx#L644-L725

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Reactions: 1
  • Comments: 20 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Maybe gettimeofday should just be replaced by using modern C++ std::chrono instead 🤷 std::chrono is certainly platform independent.

Maybe gettimeofday should just be replaced by using modern C++ std::chrono instead 🤷 std::chrono is certainly platform independent.

Yes, I also think it would simplify the code (no need to check with cmake). BTW, the issue will not be completely resolved with the PR, MINC will fail.

bool
System::GetCurrentDateTime(char date[22])
{
  const auto tp = std::chrono::system_clock::now();
  const auto s = std::chrono::time_point_cast<std::chrono::seconds>(tp);
  const auto us = std::chrono::time_point_cast<std::chrono::microseconds>(tp) -
                  std::chrono::time_point_cast<std::chrono::microseconds>(s);
  return FormatDateTime(date, std::chrono::system_clock::to_time_t(s), static_cast<long>(us.count()));
}

I now think this might be due to some Windows update, or CMake version. I tried several versions of GDCM, up to 3.0.2 from 2019, and they all run into the same compile error, in both VS2022 and VS2019.

Reproducibility 100%

It seems that on many Windows machines the build doesn’t fail, e.g. zeratul2.kitware, on the dashboard ryzenator.kitware seems to fail.

MINC build fails (similar, related to ‘time’ stuff) too. Interesting.