0

This it's causing me a headache.

I have this error linking.

g++ -o  node.o pathfinding.o prueba.o libmatrix.a -lm -lz -llog4cplus
Undefined symbols for architecture x86_64:
  "operator<(Node const&, Node const&)", referenced from:
      std::less<Node>::operator()(Node const&, Node const&) constin pathfinding.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [path] Error 1

That in the header of the class Node, out of the class declaration:

// Determine f_score in priority queue
//------------------------------------------
bool operator < (const Node &a, const Node &b);

// Determine f_score in priority queue
//------------------------------------------
bool operator > (const Node &a, const Node &b);

And in the source file (Node.cpp), I have the methods declaration:

#include "node.hpp"

// Determine f_score in priority queue
//------------------------------------------
bool operator < (const Node &a, const Node &b)
{
     return a.getf() > b.getf();
}

// Determine f_score in priority queue
//------------------------------------------
bool operator > (const Node &a,  const Node &b)
{
     return a.getf() < b.getf();
}

Anyone knows where is the problem. I'm using g++ version 4.2.1 from OSX.

Thanks in advance.

4

1 回答 1

2

你的命令有问题。该-o选项用于设置输出文件。您正在将输出文件设置为node.o,它正在覆盖您的目标文件。你的命令应该是:

g++ -o something node.o pathfinding.o prueba.o libmatrix.a -lm -lz -llog4cplus

但是您需要先重新编译node.o目标文件,因为您可能已经覆盖了它。

于 2013-05-15T12:44:00.723 回答