English 中文(简体)
未定义的引用错误对我没有任何意义
原标题:Undefined reference error doesn t make any sense to me

I have this code here:
Main.cpp

#include "AStarPlanner.h"
#include <costmap_2d/costmap_2d.h>

int main(int argc, char** argv)
{
   AStarPlanner planner =  AStarPlanner(10,10,&costmap);
}

and my class:
AStarPlanner.h

class AStarPlanner {

public:

  AStarPlanner(int width, int height, const costmap_2d::Costmap2D* costmap);
  virtual ~AStarPlanner();

< planner.cpp 的星tar Planner.cpp

#include "AStarPlanner.h"

using namespace std;

AStarPlanner::AStarPlanner(int width, int height, const costmap_2d::Costmap2D* costmap)
{

  ROS_INFO("Planner Konstruktor");
  width_ = width;
  height_ = height;
  costmap_ = costmap;
}

我无法从我身上看到任何错误。 函数是定义的, 我的主. cpp 了解该类 。

< 坚固 > CMakeList

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

rosbuild_add_library (robot_mover src/AStarPlanner.cpp )
rosbuild_add_executable(robot_mover src/main.cpp)

But i get this error :
undefined reference to vtable for AStarPlanner ** ** undefined reference toAStarPlanner::~AStarPlanner()

最佳回答

您没有定义 AstarPlanner 的毁灭器。 您可以将它添加到 AstarPlanner. cpp 中 :

AStarPlanner::~AStarPlanner()
{
}

考虑""http://www.parayft.com/c++-faq-lite/strange-inheritance.html#faq-23.10" rel="no follow" >此建议

问题回答

我也有未定义的参考问题 大多数时间都表示 连结问题...

我破解了: < / strong>

<强势> 与 Lee Netherton 写的 相似, 但直接添加到您的 CmakeLists. txt 中

确保添加执行失败函数的文件 。

举例来说,确保:

 add_executable(robot_mover 
                src/main.cpp
                AStarPlanner.cpp)

这将告诉链接器哪个源文件可以查找针对您的机器人_ mover 可执行文件的所有定义/实施...

错误意味着, 虽然编译者 < em> 能找到 main () 的分类定义, 但链接人 无法 。 您需要设置您的编译选项, 以便 Yopu 将生成的 < code> AStarPlanner. obj 传递到链接人, 当它试图构建您的可执行文件时

如何设置的确切形式取决于您正在使用什么编译器 。

使用 gcc 来编译它, 并使用类似 :

gcc -o main Main.cpp AStarPlanner.cpp

我猜你错过了 AStarPlanner.cpp 部分 。

<强>编辑:

Hugh? 你刚刚在业务方案里被改变的错误。这个答案现在说不通了。

<强>Edit2:

看起来您正在将 AstarLibrary 放到一个 robot_mover 库中。 您在构建您的可执行文件时是否连接到此库? 我并不熟悉 ros/code> 宏, 但在普通 gcc 中, 构建命令会看起来类似 :

gcc -o main Main.cpp -lrobot_mover

AstarPlanner. cpp 可能没有被编译/链接。 请确认它是否在工程中 。

您的 您的

AStarPlanner planner =  AStarPlanner(10,10,&costmap);

参考成本图,但我看不出它的定义(对于变量本身,不是对于类别)。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?