gpt4 book ai didi

c++ - 与运算符方法链接时出错

转载 作者:行者123 更新时间:2023-11-28 03:17:02 25 4
gpt4 key购买 nike

这让我很头疼。

我有这个错误链接。

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

在类 Node 的 header 中,在类声明之外:

// 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);

在源文件 (Node.cpp) 中,我有方法声明:

#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();
}

任何人都知道问题出在哪里。我正在使用来自 OSX 的 g++ 版本 4.2.1。

提前致谢。

最佳答案

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

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

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

关于c++ - 与运算符方法链接时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16565249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com