modbus icon indicating copy to clipboard operation
modbus copied to clipboard

Building modbus on Windows 11

Open AbdallaDalleh opened this issue 7 months ago • 1 comments

Environment: Windows 11 VS 2022 (latest) MSVC 143 (latest) EPICS Base 7.0.9 Modbus (latest)

We rarely build EPICS on Windows so I understand I might be missing something. I came up into building modbus and several other modules under Windows 11, everything built fine except modbus. I got compiler error C2589 on this line https://github.com/epics-modules/modbus/blob/master/modbusApp/src/drvModbusAsyn.cpp#L520 and several others, all the errors have to do with std::min. After research I came into this old thread https://stackoverflow.com/questions/5004858/why-is-stdmin-failing-when-windows-h-is-included and both these solutions work:

  1. Explicitly specify template data type, i.e. std::min<int>
  2. Use parenthesis (std::min) to prevent the MSVC preprocessor from using its own min macros.

Let me know if this is OK so I can submit a PR! 👍

AbdallaDalleh avatar Jun 16 '25 07:06 AbdallaDalleh

@AbdallaDalleh I was able to reproduce the problem. It seems to have been introduced in Windows 11, since I am sure this built fine with Windows 10.

I have pushed a fix. I also fixed several compiler warnings, and removed some residual debugging code that called errlogPrintf in readFloat64Array.

MarkRivers avatar Jun 16 '25 13:06 MarkRivers