12

我知道您已经看到 21728517 人寻求帮助,但在搜索和阅读有关此内容后,我真的无法弄清楚这个问题。我知道这个错误,我以前见过它,但是,这一次,我似乎无法绕过它。

我也试过这个清单

所以,错误:

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,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl explode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<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。我究竟做错了什么?

提前致谢。

4

1 回答 1

24

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

问题可能是由于多个 CPP 文件中的#includeing misc.h。标头保护防止标头多次包含在同一个翻译单元中,但每个 CPP 文件(通常)是一个单独的翻译单元。所以这些函数最终会被定义两次——在每个翻译单元中一次。

于 2011-11-17T16:59:27.687 回答