我今天在编写一个dll的时候出现下面的现象帮忙看看,在编写这个Dll的时候会调用到这3个lib文件 (libdes.lib agent++.lib snmp++.lib)如果我单写Point的类的Dll 编译测试没有任何问题,它同样需要引用(libdes.lib agent++.lib snmp++.lib)但是当我把sysInformation_1和computerName_1这两个类加入以后就会出现这3个link错误, 我觉得 是我在写这两个类的时候继承了 MibGroup 和 MibLeaf 这两个类的原因
但是这两个类所用的头文件和lib我已经加入到里面了,link的时候还是出现下面的错误,大家帮我看看下面的错误什么意思, 如何可以避免,主要代码我都献上了
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
const computerName_1::`vftable'" (__imp_??_7computerName_1@@6B@) referenced
in function "public: __thiscall computerName_1::computerName_1(void)"
(??0computerName_1@@QAE@XZ)
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
const sysInformation_1::`vftable'" (__imp_??_7sysInformation_1@@6B@)
referenced in function "public: __thiscall
sysInformation_1::sysInformation_1(void)" (??0sysInformation_1@@QAE@XZ)
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
public: virtual __thiscall computerName_1::~computerName_1(void)"
(__imp_??1computerName_1@@UAE@XZ) referenced in function "public: virtual
void * __thiscall computerName_1::`scalar deleting destructor'(unsigned
int)" (??_GcomputerName_1@@UAEPAXI@Z)头文件send_trap.h如下:
#include <agent_pp/mib.h>
#include <agent_pp/snmp_counters.h>
#include <string>
#include <agent_pp/agent++.h>
#include <vector>class DLL1_API Point
{
public:
void output(int c, int y);
void test();
};class DLL1_API sysInformation_1:public MibGroup
{
public:
sysInformation_1();
};class DLL1_API computerName_1:public MibLeaf
{
public:
computerName_1();
void get_request(Request*,int);
};#endif
源文件如下:
#include "send_trap.h"
#include "snmp_pp/snmp_pp.h"#define oidSysInformation_1 "1.3.6.1.2.2.0"
#define oidComputerName_1 "1.3.6.1.2.2.1.0"computerName_1::computerName_1():MibLeaf(oidComputerName_1, READONLY, new
OctetStr())
{}/**
* @brief 发送计算机名
*
* 发送计算机名
* @param req 服务器的请求
* @param index 请求的索引
* @return 无
*/void computerName_1::get_request(Request* req,int index)
{ *((OctetStr*)value) = "hellloooo!!!";
MibLeaf::get_request(req, index);
}
sysInformation_1::sysInformation_1(): MibGroup(oidSysInformation_1,
"oidSysInformation_1")
{ MibIIsnmpCounters::reset();
add(new computerName_1());}void Point::test()
{ Snmp::socket_startup();
Oid trapid("1.3.6.1.2.1.39.0");
Pdu trap_pdu;
char *key = "172.16.30.23";//strIpAddress;
int status;
Snmp *snmp1;
snmp1 = new Snmp(status, "0.0.0.0");
if ( status != SNMP_CLASS_SUCCESS)
{
//return FALSE;
}
u_short port = 162;
snmp_version version=version1;
OctetStr community("public");
//trapid = oid;
trap_pdu.set_notify_id( trapid);
UdpAddress addr(key);
addr.set_port(port);
CTarget ctarget(addr);
ctarget.set_version( version);
ctarget.set_readcommunity( community);
SnmpTarget *target = &ctarget;
Vb vb_trap(trapid);
vb_trap.set_value("5555");
trap_pdu += vb_trap;
int status1 = snmp1->trap( trap_pdu,* target);
if ( status != SNMP_CLASS_SUCCESS)
{
//return FALSE;
}
// return TRUE;
Snmp::socket_cleanup();}link时候的错误:
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
const computerName_1::`vftable'" (__imp_??_7computerName_1@@6B@) referenced
in function "public: __thiscall computerName_1::computerName_1(void)"
(??0computerName_1@@QAE@XZ)
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
const sysInformation_1::`vftable'" (__imp_??_7sysInformation_1@@6B@)
referenced in function "public: __thiscall
sysInformation_1::sysInformation_1(void)" (??0sysInformation_1@@QAE@XZ)
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
public: virtual __thiscall computerName_1::~computerName_1(void)"
(__imp_??1computerName_1@@UAE@XZ) referenced in function "public: virtual
void * __thiscall computerName_1::`scalar deleting destructor'(unsigned
int)" (??_GcomputerName_1@@UAEPAXI@Z)
如果我单写Point的类的Dll 编译测试没有任何问题,它同样需要引用
但是这两个类所用的头文件和lib我已经加入到里面了,link的时候还是出现下面的错误,大家帮我看看下面的错误什么意思, 如何可以避免,主要代码我都献上了
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
const computerName_1::`vftable'" (__imp_??_7computerName_1@@6B@) referenced
in function "public: __thiscall computerName_1::computerName_1(void)"
(??0computerName_1@@QAE@XZ)
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
const sysInformation_1::`vftable'" (__imp_??_7sysInformation_1@@6B@)
referenced in function "public: __thiscall
sysInformation_1::sysInformation_1(void)" (??0sysInformation_1@@QAE@XZ)
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
public: virtual __thiscall computerName_1::~computerName_1(void)"
(__imp_??1computerName_1@@UAE@XZ) referenced in function "public: virtual
void * __thiscall computerName_1::`scalar deleting destructor'(unsigned
int)" (??_GcomputerName_1@@UAEPAXI@Z)头文件send_trap.h如下:
#include <agent_pp/mib.h>
#include <agent_pp/snmp_counters.h>
#include <string>
#include <agent_pp/agent++.h>
#include <vector>class DLL1_API Point
{
public:
void output(int c, int y);
void test();
};class DLL1_API sysInformation_1:public MibGroup
{
public:
sysInformation_1();
};class DLL1_API computerName_1:public MibLeaf
{
public:
computerName_1();
void get_request(Request*,int);
};#endif
源文件如下:
#include "send_trap.h"
#include "snmp_pp/snmp_pp.h"#define oidSysInformation_1 "1.3.6.1.2.2.0"
#define oidComputerName_1 "1.3.6.1.2.2.1.0"computerName_1::computerName_1():MibLeaf(oidComputerName_1, READONLY, new
OctetStr())
{}/**
* @brief 发送计算机名
*
* 发送计算机名
* @param req 服务器的请求
* @param index 请求的索引
* @return 无
*/void computerName_1::get_request(Request* req,int index)
{ *((OctetStr*)value) = "hellloooo!!!";
MibLeaf::get_request(req, index);
}
sysInformation_1::sysInformation_1(): MibGroup(oidSysInformation_1,
"oidSysInformation_1")
{ MibIIsnmpCounters::reset();
add(new computerName_1());}void Point::test()
{ Snmp::socket_startup();
Oid trapid("1.3.6.1.2.1.39.0");
Pdu trap_pdu;
char *key = "172.16.30.23";//strIpAddress;
int status;
Snmp *snmp1;
snmp1 = new Snmp(status, "0.0.0.0");
if ( status != SNMP_CLASS_SUCCESS)
{
//return FALSE;
}
u_short port = 162;
snmp_version version=version1;
OctetStr community("public");
//trapid = oid;
trap_pdu.set_notify_id( trapid);
UdpAddress addr(key);
addr.set_port(port);
CTarget ctarget(addr);
ctarget.set_version( version);
ctarget.set_readcommunity( community);
SnmpTarget *target = &ctarget;
Vb vb_trap(trapid);
vb_trap.set_value("5555");
trap_pdu += vb_trap;
int status1 = snmp1->trap( trap_pdu,* target);
if ( status != SNMP_CLASS_SUCCESS)
{
//return FALSE;
}
// return TRUE;
Snmp::socket_cleanup();}link时候的错误:
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
const computerName_1::`vftable'" (__imp_??_7computerName_1@@6B@) referenced
in function "public: __thiscall computerName_1::computerName_1(void)"
(??0computerName_1@@QAE@XZ)
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
const sysInformation_1::`vftable'" (__imp_??_7sysInformation_1@@6B@)
referenced in function "public: __thiscall
sysInformation_1::sysInformation_1(void)" (??0sysInformation_1@@QAE@XZ)
agentdll error LNK2019: unresolved external symbol "__declspec(dllimport)
public: virtual __thiscall computerName_1::~computerName_1(void)"
(__imp_??1computerName_1@@UAE@XZ) referenced in function "public: virtual
void * __thiscall computerName_1::`scalar deleting destructor'(unsigned
int)" (??_GcomputerName_1@@UAEPAXI@Z)
如果我单写Point的类的Dll 编译测试没有任何问题,它同样需要引用
lz企图使用开关DLL1_API实现同一个dll头文件既能在编译dll时使用,又能提供给exe使用,但是编译dll时,lz并没有切换开关,加入语句#define DLL1_API __declspec(dllexport)。其实如果不需要把整个类导出时,不需要在类声明前加DLL1_API。