我正在尝试使用库octomap,并按照它们的GitHub中的说明进行安装。但是,当我尝试使用VSCode构建任务(使用g++)构建和运行这个简单的代码时,我会得到错误:undefined reference to `octomap::OcTree::OcTree(double)'
和其他与Octomap相关的代码的未定义引用。VSCode认识到库已经安装(当我输入#include <...>
时它会提示它),当我悬停在它们上面时,它会给我更多关于octomap函数的信息。
#include <iostream>
#include <octomap/octomap.h>
#include <octomap/OcTree.h>
using namespace std;
int main()
{
octomap::OcTree tree(0.1);
cout << "Hello, World!! \n";
return 0;
}
据我所知,Octomap头文件在/usr/local/lib/octomap/octomap/include/octomap
中。我没有经常使用C++编写代码,所以这可能只是我错过的一个新手错误。我尝试过几种方法,但仍然无法使它发挥作用。我在这里错过了什么?
提前谢谢。
发布于 2022-05-19 16:49:56
你的问题是这个程序没有连接到octomap库
使用cmake并包括以下几行:
find_package(octomap REQUIRED)
include_directories(${OCTOMAP_INCLUDE_DIRS})
target_link_libraries(${OCTOMAP_LIBRARIES})
或从命令行使用g++ <source files> -loctomap -loctomath
https://stackoverflow.com/questions/72312246
复制相似问题