Banderi
Banderi

Reputation: 710

Compilation errors: Windows API headers.... broken?

I don't know at which point it stopped working, since I've been using Code::Blocks and MinGW for the last month or so. Nonetheless, almost all of my MSVC projects (and new ones as well) have stopped working altogether now that I opened up Visual Studio again, and every time I try to build them I get hundreds of errors in the Windows API headers.

The first and most common (list of many) problems I get is coming from windows.h, after which inclusion I get this:

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winnt.h(3606): warning C4103: 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winnt.h(3908): warning C4103: 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winnt.h(4006): warning C4068: unknown pragma
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winnt.h(4012): warning C4068: unknown pragma
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winnt.h(4019): warning C4068: unknown pragma
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1482): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1482): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1483): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1483): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1483): error C2086: 'int DECLSPEC_NORETURN' : redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1482) : see declaration of 'DECLSPEC_NORETURN'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1543): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1543): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1543): error C2086: 'int DECLSPEC_NORETURN' : redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1482) : see declaration of 'DECLSPEC_NORETURN'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\rpcdce.h(369): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\rpcdce.h(369): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\rpcdce.h(369): error C2086: 'int DECLSPEC_NORETURN' : redefinition
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\winbase.h(1482) : see declaration of 'DECLSPEC_NORETURN'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\rpcdcep.h(89): error C3646: 'I_RpcAllocate' : unknown override specifier
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\rpcdcep.h(89): error C2091: function returns function
...

etc. etc. (full compilation output here)

This is similar, if not the same problem, to some I've found over the web, but still couldn't find any suitable solution out of:

It also quite reminds me of the problems I had when (dumbly) trying to compile from MSVC using the MinGW inclusions/libraries some time ago - though everything was still working properly at that point - so the best I can think of, it might be a similar issue, as in the headers became incompatible for some reason. Therefore, I thought, maybe I've installed a Win64 version over them without realizing?

I currently have MS Visual Studio 2010 Express, MS Visual Studio 2013 Express, Code::Blocks (with MinGW) and DevC++ installed. The only thing that changed in this period is that I tried out VS 2010 Ultimate (uninstalled shortly later after the trial expired) to try out some extensions, but everything worked just fine in the meanwhile, I don't know why it suddenly stopped working.

I've tried to uninstall and reinstall MSVC, Windows SDK and the DirectX SDK, but nothing worked. The environmental variables look fine, but maybe I haven't checked properly.

All the projects are in the same working state I've left them in, the environment being Win32 and all the inclusion paths being the same as before.

I really have no clue as what to do!


EDIT: Both empty projects and simple "Hello World!" programs compile & run correctly. As soon as I #include <windows.h> however, the compilation problems appear.

Upvotes: 3

Views: 2198

Answers (2)

Bogdan Cornescu
Bogdan Cornescu

Reputation: 1

I had the same problem, but with Visual Studio 2017. Before reinstalling, I tried the "Repair" function from the VS Installer, and it worked for me.

Upvotes: 0

Banderi
Banderi

Reputation: 710

Solved.

The problem was, the MinGW inclusions somehow ended up in the MSVC directory, making the compiler use those instead. Since they are Unix (POSIX) headers, the MSVC compiler can not compile them, and instead throws an exceptionally long list of errors. To solve this mess, I had to delete all the non-MSVC headers from the inclusion folders. The reason simple uninstall&reinstall didn't work is because MS uninstaller is file-specific and leaves all the non-original files in the directory. Visual Studio doesn't have, in fact, any Windows API header in the inclusion folder, and should be using the ones coming with Windows SDK.

So, since I've seen many people with this problem but no solutions to it, I'll leave the simplest answer here: In order to clean up the folder from anything not needed, you have to uninstall everything first, then manually delete those folders, and finally reinstall everything. There might be more subtle solutions that would be better if you have many additional libraries installed (I had, in fact, some) and want to delete only the specific faulting headers, leaving the rest, but I don't really know how. If anybody knows of someway to do that, like maybe a tool that checks for MSVC-compatible headers and libraries, please let me know!


EDIT: Additionally it may occur (at least in my case happened) that the VS SP1 gets also corrupted in the process, thus leading to compiler errors such as:

LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

To solve this, refer to the solutions given in this question.

Upvotes: 3

Related Questions