0

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.

CPP
  • 13
  • 2
  • 2
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix), specifically [Failure to link against appropriate libraries/object files or compile implementation files](https://stackoverflow.com/a/12574400/902497) – Raymond Chen May 20 '22 at 00:09

1 Answers1

0

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

long.kl
  • 670
  • 4
  • 12