gpt4 book ai didi

C++ Qt5 Net-snmp LNK 错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:26:43 25 4
gpt4 key购买 nike

我已经从 http://softlayer-ams.dl.sourceforge.net/project/net-snmp/net-snmp%20binaries/5.7-binaries/net-snmp-5.7.0-1.x86.exe

并安装。

现在,我正在尝试按照本教程进行说明 ( http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application )

我试图在我的 C++ Qt5 应用程序中使用 net-snmp 和 VC++ 2010 编译器,但我收到以下错误

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

我将这一行添加到我的 *.pro 文件中:

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.";
}
}

感谢您的帮助!

最佳答案

指定包含路径是不够的。当然,您需要链接库,否则链接器将无法解析所有符号。尝试

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

或类似的东西。如果库位于应用程序旁边以外的其他地方,您甚至可以指定库的绝对路径。检查库的调用方式。

关于C++ Qt5 Net-snmp LNK 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26402986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com