libmodbus icon indicating copy to clipboard operation
libmodbus copied to clipboard

Compilation error with MinGW and GCC 14

Open StalderT opened this issue 10 months ago • 0 comments

With MinGw and GCC 14 (debian 13 testsing), I have the error :

Making all in src
  CC       modbus.lo
  CC       modbus-data.lo
  CC       modbus-rtu.lo
  CC       modbus-tcp.lo
../../src/modbus-tcp.c: In function '_modbus_tcp_set_ipv4_options':
../../src/modbus-tcp.c:239:50: error: passing argument 4 of 'setsockopt' from incompatible pointer type [-Wincompatible-pointer-types]
  239 |     rc = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &option, sizeof(int));
      |                                                  ^~~~~~~
      |                                                  |
      |                                                  int *
In file included from ../../src/modbus-tcp.c:31:
/usr/share/mingw-w64/include/winsock2.h:1035:88: note: expected 'const char *' but argument is of type 'int *'
 1035 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
../../src/modbus-tcp.c: In function 'modbus_tcp_listen':
../../src/modbus-tcp.c:566:53: error: passing argument 4 of 'setsockopt' from incompatible pointer type [-Wincompatible-pointer-types]
  566 |     if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) == -1) {
      |                                                     ^~~~~~~
      |                                                     |
      |                                                     int *
/usr/share/mingw-w64/include/winsock2.h:1035:88: note: expected 'const char *' but argument is of type 'int *'
 1035 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
../../src/modbus-tcp.c: In function 'modbus_tcp_pi_listen':
../../src/modbus-tcp.c:683:58: error: passing argument 4 of 'setsockopt' from incompatible pointer type [-Wincompatible-pointer-types]
  683 |             rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
      |                                                          ^~~~~~~
      |                                                          |
      |                                                          int *
/usr/share/mingw-w64/include/winsock2.h:1035:88: note: expected 'const char *' but argument is of type 'int *'
 1035 |   WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen);
      |                                                                            ~~~~~~~~~~~~^~~~~~
make[2]: *** [Makefile:486: modbus-tcp.lo] Error 1
make[1]: *** [Makefile:505: all-recursive] Error 1
make: *** [Makefile:391: all] Error 2

This problem appeared with: https://github.com/stephane/libmodbus/commit/dde16d555621516989c9a991f2a36ba9078d9b17

StalderT avatar Jun 03 '25 13:06 StalderT