微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c – LNK2005(已定义)

我知道你已经看到21728517人要求帮助这个人,但经过搜索和阅读后,我真的不能想出这一个.我知道这个错误,我以前看过,但是,这一次,我似乎无法摆脱它.

我也试过这个checklist.

所以,错误

Error   25  error LNK2005: "void __cdecl checkStatus(unsigned int &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool)" (?checkStatus@@YAXAAIV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z) already defined in DollarRecognizer.obj C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty

Error   26  error LNK2005: "void __cdecl depth2rgb(unsigned short const *,unsigned short *,char *,int,int)" (?depth2rgb@@YAXPBGPAGPADHH@Z) already defined in DollarRecognizer.obj  C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty

Error   27  error LNK2005: "class std::vector<class std::basic_string<char,class std::allocator<class std::basic_string<char,class std::allocator<char> > > > __cdecl explode(class std::basic_string<char,char)" (?explode@@YA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@D@Z) already defined in DollarRecognizer.obj    C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty

所以,事情是,这些是在“misc.h”中用正确的#ifndef #define #endif定义的函数.他们没有在别处定义,但我仍然得到LNK2005的死亡.我究竟做错了什么?

提前致谢.

解决方法

定义misc.cpp中的函数,而不是在misc.h中.

问题可能是由于#include在多个CPP文件中的misc.h.头部保护装置防止在相同的翻译单元中多次包括标题,但是每个CPP文件(通常是)单独的翻译单元.所以这些功能最终被定义了两次 – 在每个翻译单元中一次.

原文地址:https://www.jb51.cc/c/113048.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐