Skip to content

Fix Modbus_win.cpp compilation under global WIN32_LEAN_AND_MEAN#16

Open
ros-dorian wants to merge 1 commit into
serhmarch:mainfrom
ros-dorian:bugfix/windows_includes
Open

Fix Modbus_win.cpp compilation under global WIN32_LEAN_AND_MEAN#16
ros-dorian wants to merge 1 commit into
serhmarch:mainfrom
ros-dorian:bugfix/windows_includes

Conversation

@ros-dorian

Copy link
Copy Markdown

Hi again @serhmarch :)

I want to also surface that when a global WIN32_LEAN_AND_MEAN compiler definition is defined in CMake, including the library with add_subdirectory in CMake causes a compilation error in Modbus_win.cpp.

Description

When WIN32_LEAN_AND_MEAN is defined, some headers normally included with Windows.h get discarded. Under this rule, there are two Windows headers missing in Modbus_win.cpp which causes the build to fail.

Solution

In order to be completely agnostic to compiler definitions coming from the outside world, we can define it explicitly and include the missing headers. This ensures that the file will build fine regardless of the initial state.

Environment

ModbusLib v0.5.0
Windows 11, Visual Studio 2026

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 this pull request may close these issues.

1 participant