包含 Windows 上可能存在或不存在的标头
因此,我试图处理不同版本的 Windows SDK 中的细微差异,但在编译期间无法准确确定我在 C++ 中构建的 Windows SDK 版本。
从 Windows SDK 6.1 版开始,有一个 WinSDKVer.h 文件,其中包含一些版本信息,我可以使用该信息来确定正在使用的 SDK 版本,即使它不包含 SDK 的直接版本号。但是,6.0A 不包含此头文件,因此简单地插入 #include,然后使用类似 #ifdef 之类的内容将不起作用,因为环境中没有 WinSDKVer.h。
我的一位同事模糊地记得一种在 Windows 上包含标头的方法,当且仅当它存在时,但不记得任何细节,而且到目前为止,我在 stackoverflow 或互联网上都找不到任何有关这样做的信息。
我已经对我们的 make 流程做了我能做的事情,尝试强制使用 6.1 或更高版本的 SDK(如果安装在开发人员的计算机上),但我也很感兴趣其他人之前是否遇到过这种常见问题/他们是如何解决的。
有什么想法吗?
So, I am trying to deal with small differences in the various versions of the Windows SDK but am having trouble determining during compilation precisely what version of the Windows SDK I am building against in C++.
As of version 6.1 of the Windows SDK, there is a WinSDKVer.h file that contains some version information that I could use to determine what version of the SDK is being used even though it does not contain a direct version number for the SDK. However, 6.0A does not include this header file, so simply inserting #include and then using something like #ifdef will not work since there is no WinSDKVer.h in the environment.
A colleague of mine had a vague recollection of a way to include a header on Windows if and only if it exists, but could not remember any details and I have so far failed to find any information on doing so either on stackoverflow or the internet.
I've already done what I can to our make process to try to force the use of a 6.1 or greater SDK if installed on the developer's machine, but I'm also interested if others have run into this general kind of issue before and if/how they solved it.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
(丑陋)创建您自己的空版本的头文件并将其放在文件夹中。然后将此文件夹添加到包含目录的最后。如果该文件存在于 SDK 中,则会包含该文件;否则您的文件将被使用。
(ugly) create your own empty version of the header file and place it on a folder. Then add this folder last in your include directories. if the file exists in the SDK it will be included; otherwise your file will be used.
你无法在 C++ 级别上做到这一点。您可以在构建系统级别上执行此操作 - 例如,在 SCons 中,请参阅 “检查头文件是否存在”。基本思想是编译一个仅包含该文件的小程序,然后查看编译是否成功或失败。然后你可以设置一个宏来说明你是否有标题,以及执行
什么操作。
You cannot do it on C++ level. You can do it on build system level — e.g. in SCons see "Checking for the Existence of Header Files". The basic idea is to compile a little program that just includes the file, and see whether compilation succeeds or fails. Then you can set a macro that says if you have the header, or not, and do
or whatever.
对 SDK 头文件的历史版本进行一些探索,查找所有版本的 SDK 中都存在但在不同 SDK 版本中的
#defines
中包含细微变化的头文件。您可以使用#ifdef
进行测试以区分 SDK。显然,它必须是除 WinSDKVer.h 之外的其他文件,并且在某些情况下,您可能需要多个文件的组合。
我为 Palm OS SDK 做了类似的事情< /a> 很多年前。
Do some spelunking through historic versions of the SDK headers, looking for a header file that has existed in all versions of the SDK but contains subtle variation in its
#defines
in different SDK versions. You can test these with#ifdef
to distinguish the SDKs.Obviously it'll have to be some file other than WinSDKVer.h, and in some cases you may need a combination of several files.
I did something similar for Palm OS SDKs many years ago.