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

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

问题描述

(此问题使用zlib作为示例,但不是特定的)



我试图在Windows上使用MSVC项目文件编译zlib自带。我使用VS2012与Windows 8 SDK,但我的构建机器是Windows 7。



Zlib包含以下代码:

  #ifdef IOWIN32_USING_WINRT_API 
if((filename!= NULL)&&(dwDesiredAccess!= 0))
hFile = CreateFile2 )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设置如下

  #if定义(WINAPI_FAMILY_PARTITION)&& (!(定义(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的代码可用编译。



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



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



是我唯一的方法补丁zlib添加一个检查_WIN32_WINNT> = _WIN32_WINNT_WIN8到第一行,并传递/ D_WIN32_WINNT = _WIN32_WINNT_WIN7到msbuild?这意味着我必须构建两套二进制文件 - 一个支持Win7(通过传递/ D)和一个支持Win8(不传递/ D)。



有没有办法有一个公共的二进制文件在Windows 7和8上工作,并使用CreateFile2编码路径如果在Windows 8上运行? (我想这是GetProcAddress +函数指针,还有什么吗?)

解决方案

这个问题是老的,问题,我只是通过修改(iowin32.c文件第28行)中的代码,成功地构建最新的zlib与msvc 12.0针对Windows 7。

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

当然,你需要在这里定义一个宏:
配置属性> C / C ++> :

  _WIN32_WINNT = 0x0601 

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



然后项目成功:)
和是的,当然这个修复只适用于如果你使用的窗口旧的
比windows 8。



但是,这不是zlib具有的唯一错误,您将确保在zlib.def文件中遇到不匹配的版本。
修复此错误,打开包含错误的zlib.def文件,并替换 1.2.8 1.28
或任何版本


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

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 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

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 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.

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.

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

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).

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?)

解决方案

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

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

_WIN32_WINNT=0x0601

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

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.

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天全站免登陆