C++ 语法错误:缺少“;” 编译 winnt.h 时标识符 'PVOID64' 之前
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9923628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
syntax error : missing ';' before identifier 'PVOID64' when compiling winnt.h
提问by John Snow
I've recently got the source-code on a application. When im trying to build the solution, I get an error in all parts where winnt.h
is included. The error codes differs a bit, but they always point to these lines in winnt.h:
我最近得到了一个应用程序的源代码。当我尝试构建解决方案时,我在winnt.h
包含的所有部分中都收到错误消息。错误代码略有不同,但它们始终指向 winnt.h 中的这些行:
typedef void *PVOID;
typedef void * POINTER_64 PVOID64;
and
和
struct {
DWORD crc;
BYTE rgbReserved[14];
} CRC;
So, what could be the cause of this? winnt.h is a standard header and has not been modified. Does it has something to do with me using VS 2010, or me using 64-bit windows? or is it some sort of configuration which is needed?
那么,这可能是什么原因呢?winnt.h 是标准头文件,没有被修改。这与我使用 VS 2010 或我使用 64 位 Windows 有关系吗?还是需要某种配置?
EDIT: Here's the exact error-codes:
编辑:这是确切的错误代码:
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(290): error C2146: syntax error : missing ';' before identifier 'PVOID64'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(290): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C2146: syntax error : missing ';' before identifier 'Buffer'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(8992): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11525): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11525): error C2238: unexpected token(s) preceding ';'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11556): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winnt.h(11556): error C2238: unexpected token(s) preceding ';'
采纳答案by David Heffernan
You need to include windows.h
rather than winnt.h
. When you include windows.h
it will, in turn, include winnt.h
. You need to do it this way for the necessary macros to be in place that are needed to compile winnt.h
.
您需要包含windows.h
而不是winnt.h
. 当您包含windows.h
它时,它又会包含winnt.h
. 您需要以这种方式执行此操作,以使编译所需的宏就位winnt.h
。
In this case, POINTER_64
is defined in BaseTsd.h
like this:
在这种情况下,POINTER_64
定义BaseTsd.h
如下:
#define POINTER_64 __ptr64
But if you include winnt.h
before including windows.h
then POINTER_64
is not defined.
但是,如果您在包含winnt.h
之前包含,windows.h
则POINTER_64
未定义。
回答by james82345
If you are using DirectX SDK, try changing the VC++ Directories for include and lib to be searched last.
如果您使用的是 DirectX SDK,请尝试更改 VC++ 目录,以便最后搜索 include 和 lib。
回答by Igor Chornous
It looks like your configuration of the Windows SDK is invalid. This error is caused by the fact that the compiler is unable to recognize the 'POINTER_64' statement. You may workaround this problem by replacing 'POINTER_64' with '__ptr64'.
您的 Windows SDK 配置似乎无效。此错误是由编译器无法识别 'POINTER_64' 语句这一事实引起的。您可以通过将“POINTER_64”替换为“__ptr64”来解决此问题。
I had the same issue recently. Then I've reinstalled the latest version of the Windows SDK and this fixed the problem.
我最近遇到了同样的问题。然后我重新安装了最新版本的 Windows SDK,这解决了问题。
UPDATE@David Heffernan, correctly points to the fact that one should include windows.h instead of winnt.h
更新@David Heffernan,正确地指出了一个事实,即应该包含 windows.h 而不是 winnt.h
回答by Danil
Try to remove DirectX SDK if you have one.
如果您有 DirectX SDK,请尝试删除它。
Here bug is accepted: http://connect.microsoft.com/VisualStudio/feedback/details/508204/vc10-0-errors-while-compiling-winnt-h
这里接受错误:http: //connect.microsoft.com/VisualStudio/feedback/details/508204/vc10-0-errors-while-compiling-winnt-h
回答by Andrey Rakitin
Corrected manually syntax in winnt.h :
更正了 winnt.h 中的手动语法:
typedef void * POINTER_64 PVOID64; => typedef void * POINTER_64, * PVOID64;
回答by Val
If you are using librdkafka, you will get this error whenever "Windows.h" included.
如果您使用的是 librdkafka,则只要包含“Windows.h”,您就会收到此错误。
I fixed it by rename "librdkafka/include/basetsd.h" to a different name, or access this library header via sub path!
我通过将“librdkafka/include/basetsd.h”重命名为不同的名称来修复它,或者通过子路径访问这个库头文件!
I think the author of this library made this file to deal with OS platform compatibility. But with the same file name "basetsd.h" as Windows Core, it just confusing Visual Studio.
我认为这个库的作者制作这个文件是为了处理操作系统平台兼容性。但是使用与 Windows Core 相同的文件名“basetsd.h”,它只会混淆 Visual Studio。