One or more multiply defined symbols found

后端 未结 9 624
夕颜
夕颜 2020-11-30 04:38

DebugUtil.h

#ifndef DEBUG_UTIL_H
#define DEBUG_UTIL_H

#include 

int DebugMessage(const char* message)
{
    const int MAX_CHARS = 1023;
           


        
9条回答
  •  自闭症患者
    2020-11-30 05:14

    100% Certain you correctly included Guards but still getting redefinition error?

    For Visual Studio: I was really frustrated because I was correctly included guards, only to find out the problem was visual studio. If you have added the file to your project, the compiler will add the file twice even if you have include guards around your implementation file and header file.

    If you don't use visual studio exclusively, and say... use code::blocks sometimes, you might want to only #include the file when you detect the absence of the visual studio environment.

    DebugUtil.h :
    ----------------------
    #ifndef _WIN32
    #include "DebugUtil.c"
    #endif
    ----------------------
    

    If you are okay with including stdio.h, you can be a little less hackish about it:

    DebugUtil.h :
    ----------------------
    #include 
    #ifdef _MSC_VER
    #include "DebugUtil.c"
    #endif
    ----------------------
    

    Reference: Predefined Macros, Visual Studio: https://msdn.microsoft.com/en-us/library/b0084kay.aspx

提交回复
热议问题