链接错误的未定义引用
undefined reference to linking error
我的项目中出现了"undefined reference to Mapmatcher::ransacMatches(cv::Mat, cv::Mat, Pose&)
"链接错误。我试着创建了一个MWE,如下所示,相信错误会很清楚。我的猜测是,我需要将Mapmatcher::
放在函数前面,但正如我在class Mapmatcher{}
中声明的那样,应该没有必要。
map_matcher_test_lib.h:
class Mapmatcher{
public:
Mapmatcher(void){};
void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
map_matcher_test_lib.cpp:
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
//classes
class Mapmatcher{
void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
{
// some code here...
}
};
}
map_matcher_test_node.cpp:
#include "map_matcher_test/map_matcher_test_lib.h"
Mapmatcher *mama = new Mapmatcher();
void mapMatcher()
{
// matGlob, matLoc, result known here
mama->ransacMatches(matGlob, matLoc, result);
}
int main (int argc, char** argv)
{
// some stuff...
mapMatcher();
}
感谢您的帮助。
您在头文件中有一次class Mapmatcher
,然后在源文件中又有一次,这是一个错误,违反了一次性定义规则。您应该只在头文件中有类定义,并在源文件中实现方法:
map_matcher_test_lib.h:
class Mapmatcher{
public:
Mapmatcher(void){};
void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
map_matcher_test_lib.cpp:
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
void Mapmatcher::ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
{
// some code here...
}
}
不过,请确保Mapmatcher
的类定义也在标头中的命名空间中。
相关文章:
- 编译C++时未定义的引用
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 对 Scalar ::Scalar() 的未定义引用
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 对复制 CTOR 和 CTOR 的未定义引用
- 错误:未定义对'oboe::AudioStreamBuilder::openStream(oboe::AudioStream**)'的引用
- 右值引用未定义的行为
- 对"vtable for DigitalClock"的未定义引用 - 未定义对"DigitalClock::staticMetaObject"的引用 - Qt
- 函数类型到函数类型的引用:未定义的引用
- avcodec_alloc_context引用未定义,但ffmpeg链接顺序正确
- 从c++调用Fortran子程序,链接时引用未定义
- 枚举引用未定义,但位于包含的头文件中