SNMP++ CMake Issues on Mac

Hello! I recently switched from doing development in WSL on a Windows machine to developing on a Mac. I have a simple project that uses SNMP++ for simple gets and sets which worked flawlessly in WSL but is giving me trouble on my Mac. Here’s what I’ve done:

Downloaded the SNMP++ 3.4.8 archive and extracted it
In the resulting folder, ran:

autoreconf -i
./configure
make
sudo make install
The first time I tried this I got some errors on the autoreconf that that I was using too new of an autoconf version, so I used brew to install and link the required version (2.69). Once I had autoconf version 2.69, I was able to run the installation steps without errors.

My issue now is that in my project, CMake finds SNMP++ and successfully generates build files, but when I run make it is unable to find them. More specifically, this is my CMakeLists:

cmake_minimum_required(VERSION 3.10)
project(abc)

set(CMAKE_C_COMPILER /usr/bin/cc)
set(CMAKE_CXX_FLAGS “-O3 -Wall -Wextra -Werror -pthread”)

set(CMAKE_CXX_STANDARD 17)

add_executable(tester
tests/test_main.cpp
src/a.cpp
src/b.cpp
src/c.cpp)
target_include_directories(tester PRIVATE include)

add_executable(tester2
tests/tester2.cpp
src/b.cpp
src/c.cpp)
target_include_directories(tester2 PRIVATE include)

find_library(SNMP_PP snmp++)
if(SNMP_PP)
add_definitions(-DSNMP_PP)
target_link_libraries(tester PUBLIC snmp++)
target_link_libraries(tester2 PUBLIC snmp++)
message(STATUS “SNMP++ FOUND ${SNMP_PP}”)
endif()

This finds CMake, and prints "SNMP++ FOUND /usr/local/lib/libsnmp++.dylib

When I run make, however, I get this:

make

Consolidate compiler generated dependencies of target tester

[ 11%] Building CXX object CMakeFiles/tester.dir/src/HardwareManager.cpp.o

tester2.cpp:9:10: fatal error: ‘snmp_pp/snmp_pp.h’ file not found

#include <snmp_pp/snmp_pp.h>

^~~~~~~~~~~~~~~~~~~

1 error generated.

make[2]: *** [CMakeFiles/tester.dir/src/tester2.cpp.o] Error 1

make[1]: *** [CMakeFiles/tester.dir/all] Error 2

make: *** [all] Error 2

Any ideas what could be going wrong? Thanks!

Hi,

If you want to use cmake then please do not run autoconf because autoconf might generate files that cmake will not rewrite later if it finds it (unless you do a full rebuild).

Thus, please compile and install SNMP++ using cmake if you want to build your application with cmake later.

Best regards,
Frank

Will do, thank you! Any steps I should take to remove the faulty version I’ve installed with autoconf?

Just tried to uninstall the autoconf version (did sudo make uninstall) and reinstall with cmake (mkdir build; cd build; cmake …; make; sudo make install). Still getting the same error when I try to build my project

I successfully got this to build! I made two changes:

Added /usr/local/include to my target_include_directories()
Changed target_link_libraries(tester PUBLIC snmp++) to target_link_libraries(tester PUBLIC ${SNMP_PP})

However, I’m now running into a new error. I’m using a colleague’s simple snmp agent example to test my code’s functionality, but none of the snmp++ example functions work on it. For example, here’s what I get with ./snmpGet:

% ./snmpGet localhost 1.3.6.1.2.1.1.7.0 -v1 -P20161 -C"public" -authNONE
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added auth protocol (id): (3)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added auth protocol (id): (4)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added auth protocol (id): (5)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added auth protocol (id): (6)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added auth protocol (id): (7)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added auth protocol (id): (2)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added priv protocol (id): (2)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added priv protocol (id): (4)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added priv protocol (id): (20)
20220125.09:21:39: 4399920640: (6)INFO : AuthPriv: Added priv protocol (id): (21)
20220125.09:21:39: 4399920640: (3)INFO : AuthPriv: Added default Auth and Priv protocols.
SNMP++ Get to localhost SNMPV1 Retries=1 Timeout=1000ms Community=public
20220125.09:21:39: 4399920640: (4)DEBUG : SNMPMessage: return value for build message: (0)
20220125.09:21:42: 4399920640: (6)INFO : MsgQueue: Message timed out, removed id from v3MP cache (rid): (17808)
SNMP++ Get Error, SNMP++: SNMP request timed out (-5)

This same command worked on my WSL machine previously. This is additionally complicated because the net-snmp example functions do work:

% snmpget -v1 -c public localhost:20161 1.3.6.1.2.1.1.7.0
SNMPv2-MIB::sysServices.0 = Wrong Type (should be INTEGER): Gauge32: 7

(This Wrong Type error is a known bug with my colleague’s program, he’s working on it).

Any suggestions?

Hi,
your command line should work, although you could simplify it:

If it works, when using 127.0.0.1 instead of localhost, there is an IPv4/IPv6 issue.

Regards,
Jochen

Ah using 127.0.0.1 resolved it, thank you! Seems there’s an IPv4/IPv6 issue.