user2357505
user2357505

Reputation: 81

C++ Qt5 Net-snmp LNK Error

I have downloaded net-snmp from http://softlayer-ams.dl.sourceforge.net/project/net-snmp/net-snmp%20binaries/5.7-binaries/net-snmp-5.7.0-1.x86.exe

and installed.

Now, I am trying to follow this tutorial to get stated (http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application)

I am trying to use net-snmp in my C++ Qt5 applicaton with VC++ 2010 Compiler but I get the following error

snmptest.obj:-1: Fehler: LNK2019: unresolved external symbol __imp__generate_Ku referenced in    function "public: void __thiscall SnmpTest::doSnmp(void)" (?doSnmp@SnmpTest@@QAEXXZ)

snmptest.obj:-1: Fehler: LNK2019: unresolved external symbol __imp__snmp_sess_init referenced in function "public: void __thiscall SnmpTest::doSnmp(void)" (?doSnmp@SnmpTest@@QAEXXZ)

snmptest.obj:-1: Fehler: LNK2019: unresolved external symbol __imp__init_snmp referenced in function "public: void __thiscall SnmpTest::doSnmp(void)" (?doSnmp@SnmpTest@@QAEXXZ)

C:\build\debug\a.exe:-1: Fehler: LNK1120: 4 unresolved externals

snmptest.obj:-1: Fehler: LNK2001: unresolved external symbol __imp__usmHMACMD5AuthProtocol    

I added this line to my *.pro file:

win32:INCLUDEPATH += "C:\snmp_5.7.0\include"

SnmpTest.h

#ifndef SNMPTEST_H
#define SNMPTEST_H

#include <QDebug>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/library/transform_oids.h>

class SnmpTest
{
public:
    SnmpTest();
    void doSnmp();
};

#endif // SNMPTEST_H

SnmpTest.cpp

SnmpTest::SnmpTest()
{
}

void SnmpTest::doSnmp()
{
    const char *our_v3_passphrase = "XXXXX";
    struct snmp_session session, *ss;
    struct snmp_pdu *pdu;
    struct snmp_pdu *response;

    oid anOID[MAX_OID_LEN];
    size_t anOID_len = MAX_OID_LEN;

    struct variable_list *vars;
    int status;

    /*
    * Initialize the SNMP library
    */
    init_snmp("snmpapp");

    snmp_sess_init(&session);
    session.peername = "xxxxx";
    session.version=SNMP_VERSION_3;

    /* set the SNMPv3 user name */
    session.securityName = _strdup("YYYY");
    session.securityNameLen = strlen(session.securityName);

    /* set the security level to authenticated, but not encrypted */
    session.securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;

    /* set the authentication method to MD5 */
    session.securityAuthProto = usmHMACMD5AuthProtocol;
    session.securityAuthProtoLen = sizeof(usmHMACMD5AuthProtocol)/sizeof(oid);
    session.securityAuthKeyLen = USM_AUTH_KU_LEN;

    /* set the authentication key to a MD5 hashed version of our
      passphrase (which must be at least 8
      characters long) */
    if(generate_Ku(
            session.securityAuthProto,
            session.securityAuthProtoLen,
            (u_char *) our_v3_passphrase, strlen(our_v3_passphrase),
            session.securityAuthKey,
            &session.securityAuthKeyLen) != SNMPERR_SUCCESS)
    {
        qDebug() << "Error generating Ku from authentication pass phrase.";
    }
}

Thanks for the help!

Upvotes: 1

Views: 920

Answers (1)

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53165

Specifying the include path is not enough. You need to link against the library, naturally, otherwise all the symbols will be unresolved for the linker. Try

win32 {
    INCLUDEPATH += "C:\snmp_5.7.0\include"
    LIBS+= -L"C:\snmp_5.7.0\lib" -lnetsnmp
}

or something similar. You can even specify the absolute path to the library should it be located elsewhere than beside the application. Check how exactly the library is called.

Upvotes: 1

Related Questions