使用 Windows 8 SDK 为 Windows 7 编译 [英] Using the Windows 8 SDK to compile for Windows 7

查看:27
本文介绍了使用 Windows 8 SDK 为 Windows 7 编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这个问题以 zlib 为例,但不是针对它的.)

(This question uses zlib as an example but isn't specific to it.)

我正在尝试使用它附带的 MSVC 项目文件在 Windows 上编译 zlib.我使用 VS2012 和 Windows 8 SDK,但我的构建机器是 Windows 7.

I'm trying to compile zlib on Windows using the MSVC project file it comes with. I'm using VS2012 with the Windows 8 SDK, but my build machine is Windows 7.

Zlib 包含以下代码:

Zlib contains the following code:

#ifdef IOWIN32_USING_WINRT_API
    if ((filename!=NULL) && (dwDesiredAccess != 0))
        hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
#else
    if ((filename!=NULL) && (dwDesiredAccess != 0))
        hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
#endif

其中IOWIN32_USING_WINRT_API设置如下

where IOWIN32_USING_WINRT_API is set up as follows

#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#define IOWIN32_USING_WINRT_API 1
#endif
#endif

WINAPI_FAMILY_PARTITION和WINAPI_PARTITION_APP是在Windows 8 SDK(winapifamily.h)中定义的,所以结果是zlib中使用CreateFile2的代码可以编译了.

WINAPI_FAMILY_PARTITION and WINAPI_PARTITION_APP are defined in the Windows 8 SDK (winapifamily.h), so the result is that the code that uses CreateFile2 in zlib is available to be compiled.

我可以编译 zlib,但是任何尝试加载它的应用程序都会失败,因为它找不到 CreateFile2,这是正确的,因为我的机器是 Windows 7,并且该 API 是在 Windows 8 中引入的.

I can compile zlib, but any application that tries to load it fails because it can't find CreateFile2, and rightly so, since my machine is Windows 7 and that API was introduced in Windows 8.

这是我第一次在低于它支持的 Windows 版本上使用 Windows SDK,因此我的问题是:

This is the first time I've ever used a Windows SDK on a lower version of Windows than it supports, hence my question:

我是否只能通过修补 zlib 来将 _WIN32_WINNT >= _WIN32_WINNT_WIN8 的检查添加到第一行,并将/D_WIN32_WINNT=_WIN32_WINNT_WIN7 传递给 msbuild?这意味着我必须构建两组二进制文件 - 一组支持 Win7(通过传递/D),另一组支持 Win8(通过不传递/D).

Is my only recourse to patch zlib to add a check for _WIN32_WINNT >= _WIN32_WINNT_WIN8 to the very first line, and pass /D_WIN32_WINNT=_WIN32_WINNT_WIN7 to msbuild? That would mean I'd have to build two sets of binaries - one that supports Win7 (by passing the /D) and one that supports Win8 (by not passing the /D).

如果在 Windows 8 上运行,有没有办法让通用的二进制文件在 Windows 7 和 8 上运行并使用 CreateFile2 代码路径?(我想那种方式是 GetProcAddress + 函数指针.还有别的吗?)

Is there no way to have a common binary that works on both Windows 7 and 8 and uses the CreateFile2 codepath if running on Windows 8? (I suppose that way is GetProcAddress + function pointers. Anything else?)

推荐答案

这个问题很老了,但如果有人仍然遇到这个问题,我只是通过修改 (iowin32.c文件第 28 行)像这样:

This question is old but if anyone still has this problem, I just succeded building latest zlib with msvc 12.0 targeting windows 7 by modifying the code in (iowin32.c file line 28) like so:

#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#define IOWIN32_USING_WINRT_API 1
#endif
#endif
#endif

当然要完成这项工作,您需要在以下位置定义一个宏:配置属性 >C/C++ > 预处理器:

of course to make this work you need to define a macro in: configuration properties >C/C++ > preprocessor:

_WIN32_WINNT=0x0601

这意味着您的目标是 windows 7(如果使用 windows 7 SDK,则不需要)

which means you're targeting windows 7 (if using windows 7 SDK this is not needed)

然后重建项目成功:)是的,当然,此修复程序仅适用于您使用较旧的 Windows比 Windows 8.

then rebuilding the project with success :) and yes, of course this fix is only aplicable if you're using a windows older than windows 8.

然而,这并不是 zlib 的唯一错误,您肯定会在 zlib.def 文件中遇到不匹配的版本.要解决此问题,请打开包含错误的 zlib.def 文件并将 1.2.8 替换为 1.28或任何版本

however this is not the only error that zlib has, you will for sure encounter a mismatched version in zlib.def file. to fix this open the zlib.def file that contains the error and replace 1.2.8 with 1.28 or whatever the version is

这篇关于使用 Windows 8 SDK 为 Windows 7 编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆