Build errors with Visual Studio 2019 and Windows 10

I’m currently building SNMP++ using Visual Studio 2019 Professional under Windows 10. The instructions in README.win32 help to a certain extent, so I do the following:

  • Download the SNMP++ and VS2013 archives and extract to to the required folders
  • Run autoreconf -i
  • Run ./configure
  • Delete the config_snmp_pp.h from the snmp++\include\snmp_pp folder
  • Open the Visual Studio solution and update projects to Windows 10 SDK and VS2019 format
  • Fix the include paths in the projects (some are hard-coded to a particular path).

However, I find that the code won’t build unless I make further changes to the SNMP++ source.

snmp++\include\snmp_pp\IPv6Utility.h
I need to comment out the inet_ntop declaration to prevent what appears to be a conflict with Windows 10 SDK:

1>C:\SNMP\snmp++\include\snmp_pp\IPv6Utility.h(68,14): error C2373: 'inet_ntop': redefinition; different type modifiers
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\ws2tcpip.h(593): message : see declaration of 'inet_ntop'

\snmp++\src\usm_v3.cpp
I need to replace “static_cast<pp_int64>” with “SAFE_ULONG_CAST” to fix an unknown identifier:

1>C:\SNMP\snmp++\src\usm_v3.cpp(2768,27): error C2061: syntax error: identifier 'pp_int64'
1>C:\SNMP\snmp++\src\usm_v3.cpp(2769,5): error C2143: syntax error: missing ';' before '{'
1>C:\SNMP\snmp++\src\usm_v3.cpp(2779,5): error C2181: illegal else without matching if

With these two additional changes made, I can build the solution and get the required static library, which can then be used in my application. However, I’m not sure if there should be a cleaner way to do this (maybe via an additional preprocessor definition) instead of editing the source?

Hi,

thanks for your report. The file vs2013/SNMP++/include/config_snmp_pp.h is outdated. There should be the following two typedefs, but the second one is missing:

typedef ULONGLONG pp_uint64;
typedef LONGLONG pp_int64;

Edit: the second type should be: “pp _ int64” (without the spaces), but the forum software does not like it…

For the inet_ntop function. Commenting it out is ok. Frank or I will check for a define that can be used to disable the function for the Windows 10 SDK.

Kind regards,
Jochen

Thanks Jochen, I’ve made the suggested change to config_snmp_pp.h and reverted my hack to usm_v3.cpp, this now gives a warning but builds okay.

1>C:\SNMP\snmp++\src\usm_v3.cpp(2768,63): warning C4244: 'argument': conversion from 'pp_int64' to 'long', possible loss of data

I’m not sure if this could potentially cause problems with the check_time function, I’ll report back if I see any problems in that area.

Also, I forgot to include that the inet_ntoa and inet_addr calls give the following build errors:

1>C:\SNMP\snmp++\src\notifyqueue.cpp(373,30): error C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
1>C:\SNMP\snmp++\src\snmpmsg.cpp(293,11): error C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
1>C:\SNMP\snmp++\src\snmpmsg.cpp(606,26): error C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
1>C:\SNMP\snmp++\src\uxsnmp.cpp(260,17): error C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
1>C:\SNMP\snmp++\src\uxsnmp.cpp(365,19): error C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
1>C:\SNMP\snmp++\src\uxsnmp.cpp(483,19): error C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
1>C:\SNMP\snmp++\src\uxsnmp.cpp(772,30): error C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings

For now I’ve added the suggested pre-processor definition to get a working build, but it may be that this deprecated functionality could cause problems in the future.

_WINSOCK_DEPRECATED_NO_WARNINGS

The conversion should not be a problem, because now + table[0].time_diff results in the uptime of the application in seconds, as time_diff is set to 0 - now on startup. But I think it is time to do all time calculations using 64 bit types, so I will check that.

The deprecation will also be checked.