phi*_*pvr 84 c++ compiler-errors visual-studio visual-c++
当我尝试在Win32或x64模式下使用Visual Studio 2010编译我的c ++项目时,我收到以下错误:
>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(135): fatal error C1189: #error : "No Target Architecture"
我的预处理器定义说WIN32; _DEBUG; _CONSOLE;%(PreprocessorDefinitions)
导致此错误的原因是什么?如何解决?
// 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
Run Code Online (Sandbox Code Playgroud)
更新:我创建了一个新的msvs项目并将我的代码复制到它.我不再拥有error : "No Target Architecture",但现在我有一堆涉及winnt.h和winbase.h的编译错误,并且没有涉及我的任何文件的编译错误.这些文件是否可能已损坏?我需要重新安装MSVS 2010吗?
更新2:所以我缩小了我的问题,发现它#include <WinDef.h>导致我的所有编译错误与winnt.h,但我仍然不知道如何解决它.
Nat*_*eed 20
另一个原因可能是包括依赖的标题,windows.h包括之前windows.h.
在我的情况下,我包括xinput.h在之前,windows.h并得到此错误.交换订单解决了问题.
通过首先放置以下包含文件和定义来解决它:
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 Resharper,请确保它不会为您添加错误的标头,ReSharper 非常常见的情况是:
#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.
_WIN32标识符未定义.
使用 #include <SDKDDKVer.h>
MSVS生成的项目包括这个包括通过生成包含的本地"targetver.h"包含在"stdafx.h"其中的预编译头文件"stdafx.cpp".
编辑:你的命令行上有/ D"WIN32"吗?
小智 5
Windows 10x64 专业版 19044.1586
我的案例是按 .h 文件的顺序排列的
就像这样是行不通的
#include <processthreadsapi.h>
#include <iostream>
#include <windows.h>
Run Code Online (Sandbox Code Playgroud)
但像这样工作
#include <windows.h>
#include <iostream>
#include <processthreadsapi.h>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
81698 次 |
| 最近记录: |