1. Description of the problem
Recently encountered a puzzling bug, Internet search, did not find the right solution, we have not met? So I said how to solve the problem.
I use VS2010, a solution, add a number of other people's projects, each project configuration using the library file (A.lib), compile, but one of the projects, the following error message appears:
Error C2040: "LPCH": different level of indirection for "int" and "int *" C:\Program Files (x86) \microsoftsdks\windows\v7.0a\includ E\winbase.h 3539
Error C2059: syntax error: ")" C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winbase.h 356 4
Error C2061: syntax error: identifier "lpch" C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winbase.h 14149
Error C2061: syntax error: identifier "Plong" C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winbase. H 4990
Error C2061: syntax error: identifier "Plong" C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winreg.h 742
Error C2061: syntax error: identifier "Plong" C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winreg.h 751
Error 1 C2143: syntax error: Missing ";" (In front of "*") C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 424
Error 6 C2143: syntax error: Missing ";" (In front of "*") C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 489
Error 9 C2143: syntax error: Missing ";" (In front of "*") C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 490
Error C2143: syntax error: Missing ";" (in front of "__stdcall") C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winbase.h 3539
Error C2146: syntax error: Missing ")" (in front of identifier "newenvironment") C:\Program Files (x86) \microsoftsdks\windows\v7.0a\i Nclude\winbase.h 3564
Error C2371: "short": redefined; different base types C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\wtypes.h 382
Error C2440: "Initialize": Cannot convert from "int *" to "BOOL" C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winb Ase.h 3564
Error C2440: "Initialize": Cannot convert from "int *" to "BOOL" C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winb Ase.h 3582
Error C2491: "Freeenvironmentstringsa": the definition of DllImport data is not allowed C:\Program Files (x86) \microsoftsdks\windows \v7.0a\include\winbase.h 3582
Error C2491: "Setenvironmentstringsa": the definition of DllImport data is not allowed C:\Program Files (x86) \microsoftsdks\window S\v7.0a\include\winbase.h 3564
Error C2665: "InterlockedCompareExchange": None of the 2 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\w Indows\v7.0a\include\winbase.h 15393
Error C2665: "InterlockedCompareExchange": None of the 3 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\w Indows\v7.0a\include\winbase.h 15404
Error C2665: "InterlockedDecrement": None of the 2 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\wi Ndows\v7.0a\include\winbase.h 15262
Error C2665: "InterlockedDecrement": None of the 3 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\wi Ndows\v7.0a\include\winbase.h 15271
Error C2665: "InterlockedExchange": None of the 2 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\windows\v 7.0a\include\winbase.h 15294
Error C2665: "InterlockedExchange": None of the 3 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\windows\v 7.0a\include\winbase.h 15304
Error C2665: "InterlockedExchangeAdd": None of the 2 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\wind Ows\v7.0a\include\winbase.h 15328
Error C2665: "InterlockedExchangeAdd": None of the 2 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\wind Ows\v7.0a\include\winbase.h 15338
Error C2665: "InterlockedExchangeAdd": None of the 3 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\wind Ows\v7.0a\include\winbase.h 15348
Error C2665: "InterlockedExchangeAdd": None of the 3 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\wind Ows\v7.0a\include\winbase.h 15358
Error C2665: "InterlockedIncrement": None of the 2 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\ Windows\v7.0a\include\winbase.h 15231
Error C2665: "InterlockedIncrement": None of the 3 overloads can convert all parameter types C:\Program Files (x86) \microsoft Sdks\ Windows\v7.0a\include\winbase.h 15240
Error C2733: The second C link of the overloaded function "_bittest" is not allowed C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\win Nt.h 3656
Error C2733: The second C link of the overloaded function "_bittestandcomplement" is not allowed C:\Program Files (x86) \microsoftsdks\window S\v7.0a\include\winnt.h 3662
Error C2733: The second C link of the overloaded function "_bittestandreset" is not allowed C:\Program Files (x86) \microsoftsdks\windows\v7.0a\in Clude\winnt.h 3674
Error C2733: The second C link of the overloaded function "_bittestandset" is not allowed C:\Program Files (x86) \microsoftsdks\windows\v7.0a\ Include\winnt.h 3668
Error C2733: The second C link of the overloaded function "_interlockedand16" is not allowed C:\Program Files (x86) \microsoftsdks\windows\v7.0a\incl Ude\winnt.h 3770
Error C2733: The second C link of the overloaded function "_interlockedbittestandreset" is not allowed C:\Program Files (x86) \microsoftsdks\windows \v7.0a\include\winnt.h 3686
Error C2733: The second C link of the overloaded function "_interlockedbittestandset" is not allowed C:\Program Files (x86) \microsoftsdks\windo Ws\v7.0a\include\winnt.h 3680
Error C2733: The second C link of the overloaded function "_interlockedcompareexchange16" is not allowed C:\Program Files (x86) \microsoftsdks\window S\v7.0a\include\winnt.h 3777
Error C2733: The second C link of the overloaded function "_interlockedor16" is not allowed C:\Program Files (x86) \microsoftsdks\windows\v7.0a\inc Lude\winnt.h 3783
Error 2 C4430: Missing type descriptor-assumed int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 424
Error 3 C4430: Missing type descriptor-assumed int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 424
Error 4 C4430: Missing type descriptor-assumed int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 424
Error 5 C4430: Missing type descriptor-assumed int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 424
ERROR 7 C4430: Missing type descriptor-assumed int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 489
Error 8 C4430: Missing type descriptor-assumed int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 489
Error C4430: The type specifier is missing-assumed to be int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 490
Error C4430: Missing type descriptor-assumed to be int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winnt.h 490
Error C4430: The type specifier is missing-assumed to be int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winbase.h 3539
Error C4430: The type specifier is missing-assumed to be int. Note: C + + does not support the default int C:\Program Files (x86) \microsoftsdks\windows\v7.0a\include\winbase.h 3542
2. The cause of the problem can completely ignore the last few errors, each to find a bug, should focus on the first few, the following bug, it is likely that the compiler is not perfect reason. After observation, found that the problem appears in the Winbase.h file, it is strange that the header file is a system file, there is no problem, so find the location of winbase.h, found that it was included in Windows.h, and the latter is often used in the header file. The relevant code in Windows.h is as follows:
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winuser.h>
#if ! defined (_mac) | | defined (_win32nls)
#include <winnls.h>
#endif
#ifndef _mac
#include <wincon.h>
#include <winver.h>
#endif
#if ! defined (_mac) | | defined (_win32reg)
#include <winreg.h>
#endif
#ifndef _mac
#include <winnetwk.h>
#endif
At this point, the problem is obvious, it must be the cause of the conflict between Windows.h and Winbase.h, and further, because Winbase.h is repeatedly included. 3. Problem solving other people's projects, definitely quoted Winbase.h header file, can not change others project, that can only correct their own A.lib, the results found A.lib in the header file, including windows.h, hurriedly put it into the CPP file, recompile, through!!! Or to Windows.h in A.lib, the pre-compilation limit can also be resolved. 4. Summary 1). Look at the bug to see the first few, the previous several resolved, the following bug often automatically disappear. 2). Do not suspect system files, thoroughly tempered things, will not easily have problems, problems in their own body.
3). This inexplicable error is often the reason why the header file is repeatedly included, so look carefully at the header file. Find the way, must first look at the wrong file is included in that file, one layer to find.
Programming Experience: A bug~ caused by <Windows.h>