【发布时间】:2015-02-22 19:30:06
【问题描述】:
我不断收到这个 Visual C++ 2010 LNK2005 链接器错误,说我对“Error.h”中包含的两个函数有多个定义。 (我为错误显示制作的标题)
我的项目是这样的:
BaseImage.h
BaseImage.cpp --> includes BaseImage.h , Error.h
PNGImage.h --> includes BaseImage.h
PNGImage.cpp --> includes PNGImage.h , Error.h
main.cpp --> includes PNGImage.h
当然还有Error.h:
/*
Optional macros:
AE_EXIT_AT_ERROR
*/
#pragma once
#include <stdexcept>
void aeError(const char *str, int code=1)
{
throw std::runtime_error(str);
#ifdef AE_EXIT_AT_ERROR
std::exit(code);
#endif
}
void aeAssert(bool b, const char *failStr = "assertion failed")
{
if(!b)
aeError(failStr);
}
我在每个头文件中都有#pragma once,我也尝试在 Error.h 中添加包含保护。
这是编译输出:
1>PNGImage.obj : error LNK2005: "void __cdecl aeError(char const *,int)" (?aeError@@YAXPBDH@Z) already defined in BaseImage.obj
1>PNGImage.obj : error LNK2005: "void __cdecl aeAssert(bool,char const *)" (?aeAssert@@YAX_NPBD@Z) already defined in BaseImage.obj
1>C:\...\Project.exe : fatal error LNK1169: one or more multiply defined symbols found
这可能是一个错误吗?
【问题讨论】:
标签: c++ visual-studio-2010 linker