Qt, Net-SNMP and Windows: finally married!

Long story short: i was working on a SNMP client on Qt, talking with a Cisco Access Point. I’ve already a Qt software, so i decided to add the Net-SNMP library to my project.

These are the steps to achieve the result:

  1. Download the Net-SNMP library
  2. Extract it wherever you want
  3. Download MSYS and install it
  4. Run MSYS, you will have a bash shell
  5. Now, locate the mingw compiler on Qt (see the image below)
  6. On the MSYS bash type these commands:
    1. mkdir -p /mingw
    2. mount c:/Qt/Tools/mingw730_64 /mingw (the path of the mingw you discovered on point 5.)
    3. go to the Net-SNMP source path
    4. ./configure –prefix=/mingw –without-openssl –without-perl-modules
    5. make
    6. make install
  7. Now, in the mingw Qt dir, you should have the Net-SNMP library and tools.
  8. Edit your .pro files and add this line: win32: LIBS += -L$$PWD/net-snmp/lib/ -lnetsnmp -lws2_32
Locate the mingw compiler

Now you’re ready to build your project.

Some useful tips to remind:

  1. remember to setup the env variable MIBS, for example netsnmp_setenv(“MIBS”, “+AIRESPACE-WIRELESS-MIB”, 1);
  2. remember to specify the MIBS directories, for example netsnmp_set_mib_directory(QCoreApplication::applicationDirPath().toLatin1() + “/MIBS”);
  3. if you want to understand some problem, add these lines:

snmp_set_do_debugging(1);
snmp_enable_stderrlog ();
snmp_enable_calllog();
debug_register_tokens(“read_config,get_mib,parse”);

If you need support, don’t hesitate to add a comment below.

One thought on “Qt, Net-SNMP and Windows: finally married!

  1. Ciao Roberto,
    ho provato a seguire la guida utilizzando MSYS2.

    Nel passaggio 4) del configure durante il checking build system type ho il seguente messaggio d’errore “Invalid configuration `x86_64-pc-msys’: system `msys’ not recognized”.
    A quel punto sono passato a mingw64 che mi ha consentito di terminare correttamente il configure e mi ha prodotto il makefile.

    Durante il passaggio 5) lanciando il comando make, inizialmente ho dei warning del tipo “warning: undefined symbols not allowed in x86_64-w64-mingw32 shared libraries; building static only” ed infine l’operazione termina prematuramente con il seguente messaggio:
    C:/Users/mjetr/OneDrive/Desktop/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ldl
    collect2.exe: error: ld returned 1 exit status
    make[1]: *** [Makefile:759: snmpd.exe] Error 1
    make[1]: Leaving directory ‘/c/Users/mjetr/OneDrive/Desktop/net-snmp-5.9/agent’
    make: *** [Makefile:665: subdirs] Error 1
    Lo stesso errore si ripercuote naturalmente sul make install del passaggio 6)

    Non so onestamente cosa questi errori comportino, diciamo che in ogni caso andando successivamente a vedere nella directory di mingw Qt effettivamente sono presenti dei file di Netsnmp.

    Ma quando nel mio .pro vado ad aggiungere il riferimento alle librerie del passaggio 8) nei miei sorgenti non riesco a richiamare gli header netsnmp e quindi non posso utilizzare le API netsnmp.

    Avresti qualche indicazione da darmi?

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *


The maximum upload file size: 30 MB.
You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other.
Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded.