Home > Back-end >  C - Undefined reference to octomap::OcTree::OcTree(double)'
C - Undefined reference to octomap::OcTree::OcTree(double)'

Time:05-20

I'm trying to use the library octomap and have installed according to the instructions in their GitHub. However, when I try to build and run this simple code with VSCode build task (with g ) I get the error: undefined reference to `octomap::OcTree::OcTree(double)' and other undefined references to Octomap related code. VSCode recognizes that the library is installed (it suggests it when I type #include <...> ) and gives me more information about the octomap functions when I hover over them.

#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 header files are in /usr/local/lib/octomap/octomap/include/octomap from what I can tell. I haven't coded with C a lot, so this might be just a newbie mistake that I'm missing. I've tried several approaches but still can't get it to work. What am I missing here?

Thanks in advance.

CodePudding user response:

You should setup your cpp_properties.json, look at this answer for reference

How to deal with C header file #include errors in VS Code on Mac?

CodePudding user response:

your problem is the program wasn't linked with octomap library

use cmake and include some lines like:

find_package(octomap REQUIRED)
include_directories(${OCTOMAP_INCLUDE_DIRS})
target_link_libraries(${OCTOMAP_LIBRARIES})

or from command line with g <source files> -loctomap -loctomath
refer : http://wiki.ros.org/octomap

  • Related