Fatal error: "No Target Architecture" in Visual Studio
Solution 1
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
.
Solution 2
Another cause of this can be including a header that depends on windows.h
, before including windows.h
.
In my case I included xinput.h
before windows.h
and got this error. Swapping the order solved the problem.
Solution 3
Solve it by placing the following include files and definition first:
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
Solution 4
If you are using Resharper make sure it does not add the wrong header for you, very common cases with ReSharper are:
#include <consoleapi2.h
#include <apiquery2.h>
#include <fileapi.h>
UPDATE:
Another suggestion is to check if you are including a "partial Windows.h", what I mean is that if you include for example winbase.h or minwindef.h you may end up with that error, add "the big" Windows.h instead. There are also some less obvious cases that I went through, the most notable was when I only included synchapi.h, the docs clearly state that is the header to be included for some functions like AcquireSRWLockShared but it triggered the No target architecture, the fix was to remove the synchapi.h and include "the big" Windows.h.
The Windows.h is huge, it defines macros(many of them remove the No target arch error) and includes many other headers. In summary, always check if you are including some header that could be replaced by Windows.h because it is not unusual to include a header that relies on some constants that are defined by Windows.h, so if you fail to include this header your compilation may fail.
Solution 5
_WIN32 identifier is not defined.
use #include <SDKDDKVer.h>
MSVS generated projects wrap this include by generating a local "targetver.h"
which is included by "stdafx.h"
that is comiled into a precompiled-header through "stdafx.cpp"
.
EDIT : do you have a /D "WIN32" on your commandline ?
philipvr
Updated on January 05, 2021Comments
-
philipvr over 3 years
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. -
David Heffernan over 13 yearsShould it be
_WIN32
rather thanWIN32
? It's not my area of expertise, but given that the header is looking for_WIN64
, '_AMD64_` etc. it would seem plausible. -
engf-010 over 13 years@David Heffernan : at the commandline it says WIN32 (no _) even for x84. Don't know the rationale of it (but who does understand MS)
-
David Heffernan over 13 years@Edwin x84? Is that George Orwell's computer?
-
engf-010 over 13 years@David Heffernan: yes ,big brother is watching me ! (obviously x64 i meant)
-
engf-010 over 13 yearsAMD64 will be defined under some conditions:#if !defined(68K) && !defined(MPPC) && !defined(X86) && !defined(IA64) && !defined(AMD64) && defined(_M_AMD64)
-
David Heffernan over 13 years@Edwin If
_AMD64_
or_IA64_
was defined, then he wouldn't be getting the error. That's what the header file says. -
engf-010 over 13 yearsphilipvr has updated his post. He has other (more) problems. He's thinking re-install MSVS.
-
engf-010 over 13 yearsI did think of that ,but I couldn't imaging that you didn't include windows.h.
-
engf-010 over 13 yearswindows.h defines alkinds of other defines based on compiler-switches and includes many WINAPI-headers ,some of which depending on things defned by windows.h.
-
David Heffernan over 13 yearscongratulations, you have fixed your problem and you have enough rep to vote up!
-
rsethc about 10 yearsNeither windows.h not windowsx.h (I assume them to be the same thing but have tried both anyway) help with that
#error Hey man you gotta choose a target.
. What else could fix that? -
Jens Åkerblom over 7 yearsHeads up: seems including Xinput.h before Windows.h causes this too.
-
Ari Seyhun over 6 yearsExactly my solution! Thanks for saving me hours of frustration.
-
AlastairG over 6 yearsIf I include Windows.h I get told that I cannot include it twice. Why doesn't it just ignore the second inclusion?
-
Mugen over 6 yearsIn my case it was <windows.h> instead of <winnt.h>
-
Laurie Stearn about 6 yearsAnother visit to this page arose when an old project happened to have ` #include <synchapi.h>` in a CriticalSection header.
-
Herve Mutombo almost 6 yearsIn my case _WIN32 was defined and was the culprit. I was building for x64. Your answer put me on track. Good job!
-
SWdV over 5 yearsFor me ReSharper added
consoleapi2.h
-
Jonathan Lidbeck over 4 yearsThis fixed both my x86 and x64 builds. I needed to add these lines before
#include <WinUser.h>
. -
JOE over 3 yearsI have exactly the same situation.
-
keineahnung2345 almost 3 yearsThank you. I include
windows.h
to replaceWinBase.h
andfileapi.h
.