我从以下位置下载了net-snmphttp://softlayer-ams.dl.sourceforge.net/project/net-snmp/net-snmp%20binaries/5.7-binaries/net-snmp-5.7.0-1.x86.exe
并安装。
现在,我正在尝试按照本教程中的说明进行[(C0])
我正在尝试在带有VC ++ 2010编译器的C ++ Qt5应用程序中使用net-snmp,但出现以下错误
http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application
我将此行添加到我的* .pro文件中:
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
SnmpTest.h
win32:INCLUDEPATH += "C:\snmp_5.7.0\include"
SnmpTest.cpp
#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::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.";
}
}
或类似的东西。您甚至可以指定该库的绝对路径,只要它位于应用程序之外。检查调用库的方式。
检查此指南,我遇到了同样的问题win32 {
INCLUDEPATH += "C:\snmp_5.7.0\include"
LIBS+= -L"C:\snmp_5.7.0\lib" -lnetsnmp
}