[英]'_WIN32_WINNT' / 'WINVER' : macro redefinition
I have a VS2015 C++
project.我有一个
VS2015 C++
项目。 app has to run on both Windows 7 and XP.应用程序必须在 Windows 7 和 XP 上运行。 So, I want to set
_WIN32_WINNT
& WINVER
to _WIN32_WINNT_WINXP
.所以,我想将
_WIN32_WINNT
& WINVER
设置为_WIN32_WINNT_WINXP
。
This is how stdafx.h
of my project looks like:这是我项目的
stdafx.h
的样子:
stdafx.h标准文件
#pragma once
#include "targetver.h"
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define WINVER _WIN32_WINNT_WINXP
#include <WinSDKVer.h>
// Windows Header Files:
#include <windows.h>
When compiled, I see the following warning/error:编译后,我看到以下警告/错误:
stdafx.h(12): error C2220: warning treated as error - no 'object' file generated
1>stdafx.h(12): warning C4005: '_WIN32_WINNT': macro redefinition
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include\SDKDDKVer.h(197): note: see previous definition of '_WIN32_WINNT'
1>stdafx.h(13): warning C4005: 'WINVER': macro redefinition
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include\SDKDDKVer.h(212): note: see previous definition of 'WINVER'
Because the #include "targetver.h"
is including <sdkddkver.h>
which already defines the constants _WIN32_WINNT and WINVER when they aren't already defined by the build environment. 因为
#include "targetver.h"
包含<sdkddkver.h>
,当构建环境尚未定义常量_WIN32_WINNT和WINVER时,它们已经定义了它们。
As a matter of fact, the auto-generated targetver.h
tells you exactly how to fix this: 实际上,自动生成的
targetver.h
告诉您确切的解决方法:
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>
Simple solution. 简单的解决方案。 Just define those constants before the inclusion of
targetver.h
. 只需在包含
targetver.h
之前定义这些常量。 You might have to use the actual literal value for XP since you haven't include the header file that defines 您可能必须使用XP的实际文字值,因为您没有包含用于定义XP的头文件
Like this: 像这样:
// x501 is XP
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#include "targetver.h"
#include <windows.h>
Try尝试
#include <winsdkver.h>
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#include <SDKDDKVer.h>
You #include <winsdkver.h> so you can use _WIN32_WIN_WINXP.你 #include <winsdkver.h> 这样你就可以使用 _WIN32_WIN_WINXP。 However, then you need to #undef _WIN32_WINNT because it is defined in <winsdkver.h>.
但是,您需要 #undef _WIN32_WINNT 因为它是在 <winsdkver.h> 中定义的。 That way when you use #define _WIN32_WINNT _WIN32_WINNT_WINXP you don't get the redefinition of _WIN32_WINNT warning.
这样,当您使用 #define _WIN32_WINNT _WIN32_WINNT_WINXP 时,您不会收到 _WIN32_WINNT 警告的重新定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.