Skip to content

Fix ssize_t int redefinition error on Windows#847

Open
uilianries wants to merge 1 commit intostephane:masterfrom
uilianries:fix/typedef-int-windows
Open

Fix ssize_t int redefinition error on Windows#847
uilianries wants to merge 1 commit intostephane:masterfrom
uilianries:fix/typedef-int-windows

Conversation

@uilianries
Copy link
Copy Markdown

Greetings!

When building libmodbus 3.1.12 on Windows with MSVC, the following error is listed:

C:\j\30083-4\b\libmo5c5caf0ed39b5\b\src\src\modbus-private.h(17): error C2632: 'int' followed by 'int' is illegal
make[2]: *** [Makefile:489: modbus.lo] Error 1

The full build log can be found here: https://c3i.jfrog.io/artifactory/cci-build-logs/cci/prod/PR-30083/4/package_build_logs/build_log_libmodbus_3_1_12_b07e4eebf5b5cd0ff2c2ef1dc2a0bfbe_19e318a866610969ae17aaa36552350ac86725f0.txt

We noted that error when packaging libmodbus for Conan Center, on the PR conan-io/conan-center-index#30083. And may be related to 23dd803

As the type ssize_t is POSIX, when running configure on Windows, the setup can't find ssize_t via AC_TYPE_SSIZE_T and writes #define ssize_t int into config.h as a result. Then, when config.h gets included before that typedef, the preprocessor expands typedef int ssize_t into typedef int int, which is invalid by the msvc compiler.

This PR adds a guard to prevent redefining ssize_t, so mitigating this error as on Linux and other will not have effect, but on Windows will really consume the already defined ssize_t from config.h. This idea is actually being used by the Conan recipe for libmodbus on previous version too.

I tested this patch locally, over libmodbus 3.1.12 on Windows: libmodbus-3.1.12-windows-amd64-msvc194-release-static-patched.log

Regards!

Environment

OS: Windows
CPU: x86_64
Build type: Release
Compiler: Visual Studio - MSVC 194
Libmodbus version: 3.1.12

Mitigates the MSVC error:
src\modbus-private.h(19): error C2632: 'int' followed by 'int' is
illegal

ssize_t is defined already on MSVC which causes the error

Signed-off-by: Uilian Ries <uilianries@gmail.com>
@cla-bot
Copy link
Copy Markdown

cla-bot Bot commented May 4, 2026

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

@uilianries
Copy link
Copy Markdown
Author

uilianries commented May 4, 2026

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

Done. The CLA form has been filled and sent. Regards!

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