Fatal error: “No Target Architecture” in Visual St

2019-01-11 05:24发布

When I try to compile my c++ project using Visual Studio 2010 in either Win32 or x64 mode I get the following error:

>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(135): fatal error C1189: #error : "No Target Architecture"

My preprocessor definitions say WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)

What is causing this error and how do I fix it?

// winnt.h: lines 127-136, MSVS says this is an inactive preprocessor block
#if defined(_WIN64)

#if defined(_AMD64_)
#define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( DWORD )
#elif defined(_IA64_)
#define PROBE_ALIGNMENT( _s ) (TYPE_ALIGNMENT( _s ) > TYPE_ALIGNMENT( DWORD ) ? \
                              TYPE_ALIGNMENT( _s ) : TYPE_ALIGNMENT( DWORD ))
#else
#error "No Target Architecture"
#endif

Update: I created a new msvs project and copied my code to it. I no longer have error : "No Target Architecture", but now I have a bunch of compile errors involving winnt.h and winbase.h and no compile errors involving any of my files. Is it possible these files are corrupted? Do I need to reinstall MSVS 2010?

Update 2: So I narrowed down my problem and found that it is #include <WinDef.h> that is causing all of my compile errors with winnt.h but I still don't know how to fix it.

9条回答
对你真心纯属浪费
2楼-- · 2019-01-11 05:51

It would seem that _AMD64_ is not defined, since I can't imagine you are compiling for Itanium (_IA64_).

查看更多
别忘想泡老子
3楼-- · 2019-01-11 05:51

https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2017InstallerProjects

need to install this to get rid of this issue , take fresh smaple code then compile ...

查看更多
贪生不怕死
4楼-- · 2019-01-11 05:58

Use #include <windows.h> instead of #include <windef.h>.

From the windows.h wikipedia page:

There are a number of child header files that are automatically included with windows.h. Many of these files cannot simply be included by themselves (they are not self-contained), because of dependencies.

windef.h is one of the files automatically included with windows.h.

查看更多
狗以群分
5楼-- · 2019-01-11 05:58

Besides causes described already, I received this error because I'd include:

#include <fileapi.h>

Apparently it was not needed (despite of CreateDirectoryW call). After commenting out, compiler was happy. Very strange.

查看更多
Animai°情兽
6楼-- · 2019-01-11 05:59

Another reason for the error (amongst many others that cropped up when changing the target build of a Win32 project to X64) was not having the C++ 64 bit compilers installed as noted at the top of this page.
Further to philipvr's comment on child headers, (in my case) an explicit include of winnt.h being unnecessary when windows.h was being used.

查看更多
女痞
7楼-- · 2019-01-11 06:03

I had a similar problem. In my case, I had accidentally included winuser.h before windows.h (actually, a buggy IDE extension had added it). Removing the winuser.h solved the problem.

查看更多
登录 后发表回答