0

I have a class Node declared in node.h. The methods are defined in node.cc. I have another class Tree declared in tree.h, with its methods defined in tree.cc.

The insertPoint method in tree creates a Node* node variable and calls the insertNode method with node as a parameter. The insertNode in turn invokes various methods of the Node class such as addChild, setLevel, getMinDist etc, for example: node->getMinDist(...), node->setLevel(...)

Full source is here : https://github.com/apoorvreddy/covertree

class Node {
private:
  Point *point;
  int level;
  std::vector<Node*> children;

public:
  Node(Point *p) {
    point = p;
  }

  Node(Point* p, int l) {
    point = p;
    level = l;
  }

  ~Node();

  Point* getPoint();
  std::vector<Node*> getChildren();
  int getLevel();
  void setLevel(int l);
  void addChild(Node *n);
  double getDistance(Node* node);
  double getMinDist(std::vector<Node*> nodeList);

};



class Tree {
private:
  float base;
  int maxLevel;
  int minLevel;
  Node* root;
  std::vector<Point> pointSet;
  bool insertNode(Node* node, std::vector<Node*> coverset_qi, int level);
public:
  Tree();
  void insertPoint(Point& point);
 };

However when I try to compile this code, I get the following error. What am I doing wrong !?

Undefined symbols for architecture x86_64:

"Node::getMinDist(std::__1::vector >)", referenced from:

 Tree::insertNode(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >, int) in tree.o

"Node::getChildren()", referenced from:

 Tree::insertNode(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >, int) in tree.o

"Node::getDistance(Node*)", referenced from:

 Tree::insertNode(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >, int) in tree.o

"Node::addChild(Node*)", referenced from:

 Tree::insertNode(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >, int) in tree.o

"Node::getLevel()", referenced from:

 Tree::insertNode(Node*, std::__1::vector<Node*, 

std::__1::allocator >, int) in tree.o

"Node::getPoint()", referenced from:

 Tree::insertNode(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >, int) in tree.o

"Node::setLevel(int)", referenced from:

 Tree::insertNode(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >, int) in tree.o
Apoorv
  • 11
  • 4
  • 1
    Where is the definiton of these functions? How does your compiler command line look? – user0042 Aug 25 '17 at 07:46
  • Hi, I've defined these functions in different files namely node.cc and tree.cc. For the sake of brevity, I have not pasted them here. I'm compiling this using a Makefile. This is the relevant part of the makefile. `point.o: point.cc point.h` `$(CC) -c -o point.o point.cc $(CFLAGS)` `node.o: node.cc node.h` `$(CC) -c -o node.o node.cc $(CFLAGS)` `tree.o: tree.cc tree.h node.o point.o` `$(CC) -c -o tree.o tree.cc $(CFLAGS)` – Apoorv Aug 25 '17 at 07:47
  • More important is my second question. – user0042 Aug 25 '17 at 07:48
  • Hi, this is the link to my source: https://github.com/apoorvreddy/covertree – Apoorv Aug 25 '17 at 07:57
  • there is no node.o in your linker list of objects $(CC) -g -v -o knn cli_main.cc utils.o point.o covertree.o $(CFLAGS) – Artemy Vysotsky Aug 25 '17 at 08:00
  • Thank you !! I don't know how I missed it ! It compiles now :) – Apoorv Aug 25 '17 at 08:01

0 Answers0