-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Missing includes in ModbusServerPort_p.h causes build failure with bcc64x compiler
Environment
- ModbusLib Version: 0.4.6
- Compiler: Embarcadero bcc64x (Clang 20.1.7 based) - RAD Studio 37.0
- Platform: Windows 64-bit
- Build System: CMake 4.1.1 with Ninja
Description
Building ModbusLib 0.4.6 with the Embarcadero bcc64x compiler fails due to missing header includes in src/ModbusServerPort_p.h. The file uses malloc, free, and memcpy functions without including the required standard library headers.
Error Output
[6/27] Building CXX object src/CMakeFiles/modbus.dir/ModbusServerPort.cpp.o
FAILED: src/CMakeFiles/modbus.dir/ModbusServerPort.cpp.o
In file included from J:/Projects/BravoSystems/SVN/3rdparty/ModBusLib/ModbusLib-0.4.6/src/ModbusServerPort.cpp:24:
Error E5199 J:/Projects/BravoSystems/SVN/3rdparty/ModBusLib/ModbusLib-0.4.6/src\ModbusServerPort_p.h 50(13): use of undeclared identifier 'free'
50 | free(settings.unitmap);
| ^
Error E5199 J:/Projects/BravoSystems/SVN/3rdparty/ModBusLib/ModbusLib-0.4.6/src\ModbusServerPort_p.h 63(13): use of undeclared identifier 'free'
63 | free(settings.unitmap);
| ^
Error E5200 J:/Projects/BravoSystems/SVN/3rdparty/ModBusLib/ModbusLib-0.4.6/src\ModbusServerPort_p.h 66(59): use of undeclared identifier 'malloc'; did you mean '_alloca'?
66 | settings.unitmap = reinterpret_cast<uint8_t*>(malloc(MB_UNITMAP_SIZE));
| ^~~~~~
| _alloca
Similar errors occur in:
ModbusServerResource.cppModbusTcpServer.cppwin/ModbusTcpServer_win.cpp
Root Cause
The file src/ModbusServerPort_p.h uses the following standard C functions without including their headers:
mallocandfree(line 50, 63, 66) - require<cstdlib>or<stdlib.h>memcpy(line 67) - requires<cstring>or<string.h>
While GCC and some other compilers may include these headers transitively, the bcc64x compiler requires explicit includes.
Proposed Fix
Add the missing includes at the top of src/ModbusServerPort_p.h:
#ifndef MODBUSSERVERPORT_P_H
#define MODBUSSERVERPORT_P_H
#include <cstdlib> // for malloc, free
#include <cstring> // for memcpy
#include "ModbusObject_p.h"Testing
After applying this fix, ModbusLib 0.4.6 builds successfully with bcc64x:
- Static library build completes without errors
- All 27/27 build targets succeed
- Library file generated:
libmodbus.a
Impact
This issue affects any build environment using compilers with stricter header inclusion requirements. The fix is minimal, follows C++ best practices (explicit includes), and has no negative impact on other compilers.
Additional Information
- This issue does not affect GCC or standard Clang builds due to transitive header inclusion
- The fix follows standard C++ practices of explicitly including headers for used functions
- No changes to functionality, only header includes