首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >请求成员‘in’,这是non_clas.Vtable,Linker错误?

请求成员‘in’,这是non_clas.Vtable,Linker错误?
EN

Stack Overflow用户
提问于 2016-09-08 07:00:38
回答 1查看 151关注 0票数 0

当我在一个-std=c++11机器上用代码::块16.01构建我的项目(gnu g cc,-std=c++11)时,项目中包含了头文件,我得到以下错误:

Snmp_pp::UdpAddress‘path..\src\Main.cpp|77|undefined对Snmp\_pp::UdpAddress::UdpAddress(char const\*)'| path..\snmp\_pp\address.h|574|undefined reference tovtable的引用

还有很多其他未定义的参考错误。

这里是我的代码的部分,有很多注释行,我跳过了它们。

main.cpp:

代码语言:javascript
复制
#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);

H是定义的UdpAddress类,这是代码的一部分

代码语言:javascript
复制
 //------------------------------------------------------------------------
 //---------[ 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公司。

链接到页面

我的文件夹结构是:

代码语言:javascript
复制
main_dir\src\main.cpp   
main_dir\libsnmp.h   
main_dir\snmp_pp\all other header files  

这是我的构建输出:

代码语言:javascript
复制
  g++.exe -Wall -std=c++11 -g -std=c++11 -I"C:\Users\Kneringer Georg\Documents\CodeBlocks\SNMP_ZIM" -I"C:\Users\Kneringer Georg\Documents\CodeBlocks\SNMP_ZIM\snmp_pp" -c "C:\Users\Kneringer Georg\Documents\CodeBlocks\SNMP_ZIM\src\Main.cpp" -o obj\Debug\src\Main.o

我需要帮助去理解我做错了什么。我想这是链接器的错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-08 07:15:22

在每个库(几乎)中,我们有两个主要组件:

  • 包含库中公共函数声明的头文件
  • 定义函数的实现文件

通过包含头文件,您可以告诉编译器,我有这些函数供我使用,您可以使用它们。在链接阶段,链接器将试图找到这些函数的实现,但是它找不到它们,这就是为什么会出现错误。

为了修复错误,需要在IDE中配置链接器路径,告诉他这是包含函数的lib。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39384465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档