请求会员non_clas...Vtable,链接器错误?
request for member ' ' in ' ' which is of non_clas... Vtable, Linker error?
当我在Win10 x64机器上在Code::BLocks 16.01中构建我的项目(gnu g cc, -std=c++11)时,头文件包含在项目中,我得到以下错误:
path. srcMain.cpp|77|未定义引用' Snmp_pp::UdpAddress::UdpAddress(char const*)'|
path..snmp_ppaddress.h|574|未定义引用' vtable for snmp_pp::UdpAddress'|
我得到很多其他未定义的引用错误。
这是我的代码部分,有很多注释行,我跳过了它们。
main.cpp:
#include <stdio.h>
#include "libsnmp.h"
#include "snmp_pp/snmp_pp.h"
using namespace Snmp_pp;
int main (){
long rc;
char buf [256];
char const* ip_address;
ip_address = "192.168.127.250";
Snmp socket_startup();
//Socket Informationen
//Here comes line 77***************************
UdpAddress udp_address(ipaddr);
snmp_version version = version1;
int retries = 1;
int timeout = 100;
u_short port = 161;
OctetStr community ("public");
//SNMP Session öffnen
int status;
Snmp snmp(status, 0,(udp_address.get_ip_version()==Address::version_ipv4));
//SNMP Header Variablen ASN.1 encoding
Pdu pdu;
Vb vb;
//Erstelle OID Objekte
Oid oid("1.3.6.1.2.1.1.1.0"); //sysDescr
vb.set_oid(oid);
pdu+= vb;
**Here comes Line 100**
udp_address.set_port(port);
**Here comes Line 102**
CTarget ctarget(udp_address);
ctartget.set_version(version);
ctartget.set_retry(retries);
ctartget.set_timeout(timeout);
ctartget.set_readcommunity(community);
SnmpTarget *target;
target = &ctartget;
status = snmp.get(pdu, *target);
address.h这是定义的UdpAddress类,这是代码的一部分
//------------------------------------------------------------------------
//---------[ UDP Address Class ]------------------------------------------
//------------------------------------------------------------------------
class DLLOPT UdpAddress : public IpAddress
{
public:
/**
* Construct an empty invalid UDP address.
*/
UdpAddress();
/**
* Construct an UDP address from a string.
*
* The following formats can be used additional to those recognized by
* IpAdress:
* - Port added to IPv4 address with '/' or ':'
* ("192.168.17.1:161", "192.168.17.1/161", "printsrv/161")
* - Port added to IPv6 address with '/' or using '[...]:'
* ("::1/162", "[::1]/162", "[::1]:162")
*
* @param inaddr - Hostname or IP address
*/
UdpAddress(const char *inaddr);
/**
* Construct an UDP address from another UDP address.
*
* @param udpaddr - address to copy
*/
UdpAddress(const UdpAddress &udpaddr);
/**
* Construct an UDP address from a GenAddress.
*
* @param genaddr - address to copy
*/
UdpAddress(const GenAddress &genaddr);
/**
* Construct an UDP address from a IP address.
* The port will be set to 0.
*
* @param ipaddr - address to copy
*/
UdpAddress(const IpAddress &ipaddr);
/**
* Return the IP version of the address.
*
* @return one of Address::version_type
*/
virtual version_type get_ip_version() const { return ip_version; }
/**
* Construct an UDP address from a GenAddress.
*
* @param genaddr - address to copy
*/
UdpAddress(const GenAddress &genaddr);
/**
* Construct an UDP address from a IP address.
* The port will be set to 0.
*
* @param ipaddr - address to copy
*/
UdpAddress(const IpAddress &ipaddr);
/**
* Destructor (ensure that SnmpSyntax::~SnmpSyntax() is overridden).
*/
~UdpAddress() {}
包含的头文件来自于SNMP++3.3.7项目中的HP公司
链接到网页
我的文件夹结构是:
main_dirsrcmain.cpp
main_dirlibsnmp.h
main_dirsnmp_ppall other header files
以下是我的构建输出:
g++.exe -Wall -std=c++11 -g -std=c++11 -I"C:UsersKneringer GeorgDocumentsCodeBlocksSNMP_ZIM" -I"C:UsersKneringer GeorgDocumentsCodeBlocksSNMP_ZIMsnmp_pp" -c "C:UsersKneringer GeorgDocumentsCodeBlocksSNMP_ZIMsrcMain.cpp" -o objDebugsrcMain.o
我需要帮助来理解我做错了什么。我猜这是一个链接器错误
在几乎每个库中,我们都有两个主要组件:
- 包含库中公共函数声明的头文件
- 定义函数的实现文件
通过包含头文件,你告诉编译器,我有这些函数供我使用,你可以使用它们。在链接阶段,链接器将尝试找到这些函数的实现,但它没有找到它们,这就是为什么会出现这个错误。
为了修复这个错误,您需要在IDE中配置链接器路径,告诉他这是包含函数的库。
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- Visual Studio mkl_link_tool.exe链接错误
- C++ 实现模板单例类时出现链接错误
- 使用类模板的方法链接错误
- MySQL C++连接器链接错误
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- 运行 C++ 单元测试时LNK2005链接错误
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 链接错误,包括我创建的相同头文件 - C++
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 使用标头保护的多个定义链接错误
- 链接错误:未定义对 stdscr 和 wgetch 的引用
- 使用 Vivek 的 Vcam / 捕获源过滤器构建/链接错误
- 升压program_options中的链接错误
- 使用 g++ 预处理器进行替换会导致链接错误
- 在调试配置中编译工作正常,但发布会给出链接错误
- 相邻矩阵设置链接错误
- 包含常量变量并包含在多个文件中的标头的链接错误
- C++链接错误,我理解但无法解决
- 是什么导致macOS Mojave上的GoogleTest链接错误