Author Topic: Incorrect redefinition error.  (Read 6644 times)

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Incorrect redefinition error.
« on: August 26, 2011, 12:21:53 am »
Hello. I was unsure what forum reporting this bug would be appropriate in.

On windows vista, Code::Blocks 10.05. It is incorrectly reported that a redefinition error occurs:

Code
D\main.cpp||In function 'const bool DeleteFileA(const char*)':|
D\main.cpp|12|error: new declaration 'const bool DeleteFileA(const char*)'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\winbase.h|1291|error: ambiguates old declaration 'BOOL DeleteFileA(const CHAR*)'|
||=== Build finished: 2 errors, 0 warnings ===|

Notice that it says 'DeleteFileA'. The problem is, my function is just called 'DeleteFile' (there is no A in it), and that there is somehow a redefinition error between 'DeleteFile' (which it mistakenly calls DeleteFileA) and 'DeleteFileA'.

Below is the code to reproduce the problem:

Code
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <windows.h>
#include <winbase.h>

const bool DeleteFile(const char FileName[])
{
    if(remove(FileName) != 0)
    {
        return false;
    }
    return true;
}

int main(int ArgC, char *ArgV[])
{
    return 0;
}

I have also uploaded a screenshot of both the code and the failed compilation attempt:
http://img844.imageshack.us/img844/6443/compilebug.jpg


Whilst I know this forum distinguishes between IDE and compiler, I am absolutely confused by everything, and wasn't sure where best to post this, given this redefinition error shouldn't be occurring at all. I would understand if 'DeleteFile' conflicted with an earlier version of 'DeleteFile', but it's somehow conflicting with 'DeleteFileA' instead.


I will add: If 'DeleteFile' is declared before winbase.h, no such redefinition conflict error occurs.
« Last Edit: August 26, 2011, 12:25:42 am by Joshua Flynn »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Incorrect redefinition error.
« Reply #1 on: August 26, 2011, 01:25:51 am »
Your question is not related to C::B, but to th euse of MinGW and overriding functions.
If you click on the second part of the errormessage, it will lead you to the original declaration of DeleteFileA, and some lines above (at least in my cross-compiling headers on linux), you see that DeleteFile is a define:
Code
#define DeleteFile __MINGW_NAME_AW(DeleteFile)

and if you right-click on __MINGW_NAME and chose goto declaration it leads you to

Code
# define __MINGW_NAME_AW(func) func##A
.

So the error message is absolutely correct, if you would use unicode, the name would be DeleteFileW .

I gave you an aswer to the question, even if it violates our forum rules (bnot C::B releated), but it shows you how to use the power of Code::blocks to find analyze an error.

Offline Joshua Flynn

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Incorrect redefinition error.
« Reply #2 on: August 26, 2011, 01:39:06 am »
Thank you for your help Jens. I'll let you deal with the thread as you see fit.