Fatal error: “No Target Architecture” in Visual Studio

前端 未结 11 2178
慢半拍i
慢半拍i 2020-11-29 05:52

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 SDK

相关标签:
11条回答
  • 2020-11-29 06:06

    At the beginning of the file you are compiling, before any include, try to put ONE of these lines

    #define _X86_
    #define _AMD64_
    #define _ARM_
    

    Choose the appropriate, only one, depending on your architecture.

    0 讨论(0)
  • 2020-11-29 06:07

    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.

    0 讨论(0)
  • 2020-11-29 06:08

    _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 ?

    0 讨论(0)
  • 2020-11-29 06:10

    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.

    0 讨论(0)
  • 2020-11-29 06:11

    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>
    
    0 讨论(0)
  • 2020-11-29 06:11

    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.

    0 讨论(0)
提交回复
热议问题