在编译时产生错误:
TestProject.obj : error LNK2005: "void __cdecl ReportError(unsigned long)" (?ReportError@@YAXK@Z) already defined in MailDlg.obj
TestProjectDlg.obj : error LNK2005: "void __cdecl ReportError(unsigned long)" (?ReportError@@YAXK@Z) already defined in MailDlg.obj
ReportError是我在Global.h中定义的一个全局函数,在Global.h中已经定义了只包含一次啊:
#ifndef GLOBAL__H
#define GLOBAL__H
void ReportError(....)
....
#endif
然后在上述几个头文件中包含了Global.h,但编译时还是出现了错误,这是为什么?

解决方案 »

  1.   

    Global.h最好包含在cpp文件中,以免多次包含
      

  2.   

    TestProjectDlg.cpp:
    #include "stdafx.h"
    #include "TestProject.h"
    #include "TestProjectDlg.h"
    #include "WBButton.h"
    #include "MailDlg.h"
    #include "GMouseHooK\GMouseHook.h"
    #include "socketx.h"
    #include "CBase64.h"
      

  3.   

    ReportError(....)放到一个cpp中,然后在。h中定义。#ifndef GLOBAL__H
    #define GLOBAL__H
    只能保证被编译一次,不是说只能被使用一次,多个。cpp都可以使用,所以会重复包含
      

  4.   

    这个问题好像是在你实现void ReportError(....)的那个cpp中没包含stdafx.h
    可能Rebuild All就没事了。
      

  5.   

    ReportError的实现应该放在cpp文件中。