C++项目中出现错误LNK2005
Error LNK2005 in C++ project
由于错误LNK2005 ,我的功能出现问题
void createNetwork(Link **linkTable, Router **router, Computer **computer) {
router = new Router*[5];
linkTable = new Link*[11];
computer = new Computer*[6];
//---------------------------------------------------------------
router[0] = NULL;
//---------------------------------------------------------------
router[1] = new Router(1);
router[1]->link = new Link*[4];
....
错误:
1>device.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (? createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Link.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Packet.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Queue.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Router.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>sc.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Time.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>E:DokumentySymulacja - Projekttrunkf4_sk_zelek_witDebugf4_sk_zw.exe : fatal error LNK1169: one or more multiply defined symbols found
我试着把它修好,但没用。有人能告诉我该怎么修吗?Thx:)
如果要在标头中定义函数,请将其标记为inline
,以允许在包含标头的每个翻译单元中进行定义。
或者,将定义移动到源文件中,使其只定义一次。
相关文章:
- 错误LNK2005无法解决问题的解决方案
- C++错误LNK2005和不同项目文件的常规继承
- 使用 AMD 的 Vulkan 内存分配器时出现链接器错误 (LNK2005)
- 错误LNK2005结构已在.obj文件中定义
- 错误 LNK2005:构造函数已定义
- 重新定义函数,同时将文件包含在C++中(错误 LNK2005)
- 使用Visual Studio的Windows中的链接器错误(LNK2005)
- C++ 错误LNK2005和错误LNK1169
- 错误LNK2005和错误LNK2019
- 错误 11 错误 LNK2005:已在 MyForm.obj 中定义"class cv::Mat imageOutput" (?imageOutput@@3VMat@cv@@A)
- 错误LNK2005构造函数已定义
- 错误 LNK2005:"class Player m_player"已在 Game.obj 中定义
- 错误LNK2005,已定义
- 错误 LNK2005:"already defined in SkinHeaderCtrl.obj"
- 链接错误LNK2005多个CUDA文件
- 链接文件错误,VS 2015中的错误LNK2005
- 当包含全局函数时,c++错误lnk2005
- 错误LNK2005:已在hold.obj中定义_main
- 错误 LNK2005:已在 functions.obj 中定义"int __cdecl number(void)" (?number@@YAHXZ)
- 添加新头文件时出现C++错误LNK2005