安装wdk后对ms c++命令行编译器的影响

浪费了好几小时,我的QT编译不了,提示:fatal error C1083: 无法打开包括文件: “corecrt.h”: No such file or directory

这应该是一个微软造成的一个BUG。

估计所有靠vcvarsall.bat的编译器都会有这个问题吧,比如:make,gyp,ninja等

之前明明是好的,这种情况感觉是找不到SDK了,或者 SDK目录有问题。想了昨天 晚上安装 了WDK,可能是这个的原因 ,于是把WDK卸载果然好了。

经过仔细研究发现,安装WDK之后 会使include和lib环境变量出错("VS2015 x64 Native Tools Command Prompt)。

这个命令会运行:"%VSInstallDir%\VC\vcvarsall.bat", which eventually
calls "%VS140COMNTOOLS%\vcvarsqueryregistry.bat"。这个vcvarqueyryregistry.bat通过遍历试图去查找%ProgramFiles(x86)%\Windows Kits\10\include来查找 windows sdk版本的目录 ,查是WDK在这里面是一个例外,他会使这个遍历查找SDK的代码出错。.

image

然后WindowsSDKVersion,WindowsSDKLibVersion,UCRTVersion这几个变量都会错误的设置为WDF,这是导致编译器找不到头文件和LIB文件的根本原因。

https://stackoverflow.com/questions/31862627/vs2015-cl-cant-find-crt-libs-stdio-h-ctype-h-etc-when-building-on-command-l

解决方案:

1.卸载WDK
2.使用下面该当临时进行修复

修改vcvarsqueryregistry.bat代码

@REM Get windows 10 sdk version number
-@if not "%WindowsSdkDir%"=="" @FOR /F "delims=" %%i IN ('dir
"%WindowsSdkDir%include\" /b /ad-h /on') DO @set WindowsSDKVersion=%%i\
+@if not "%WindowsSdkDir%"=="" @set WindowsSDKVersion=10.0.10240.0\
@if not "%WindowsSDKVersion%"=="" @SET WindowsSDKLibVersion=%WindowsSDKVersion%
@if not "%WindowsSdkDir%"=="" @set
WindowsLibPath=%WindowsSdkDir%UnionMetadata;%WindowsSdkDir%References;%WindowsSdkDir%References\Windows.Foundation.UniversalApiContract\1.0.0.0;%WindowsSdkDir%References\Windows.Foundation.FoundationContract\1.0.0.0;%WindowsSdkDir%References\indows.Networking.Connectivity.WwanContract\1.0.0.0
@@ -71,7 +71,7 @@
)
)
@REM get windows 10 sdk version number
-@if not "%WindowsSdkDir%"=="" @FOR /F "delims=" %%i IN ('dir
"%WindowsSdkDir%include\" /b /ad-h /on') DO @SET WindowsSDKVersion=%%i\
+@if not "%WindowsSdkDir%"=="" @set WindowsSDKVersion=10.0.10240.0\
@if not "%WindowsSDKVersion%"=="" @SET WindowsSDKLibVersion=%WindowsSDKVersion%
@if not "%WindowsSdkDir%"=="" @set
WindowsLibPath=%WindowsSdkDir%UnionMetadata;%WindowsSdkDir%References;%WindowsSdkDir%References\Windows.Foundation.UniversalApiContract\1.0.0.0;%WindowsSdkDir%References\Windows.Foundation.FoundationContract\1.0.0.0;%WindowsSdkDir%References\indows.Networking.Connectivity.WwanContract\1.0.0.0
@@ -289,7 +289,7 @@
)
)
@if "%UniversalCRTSdkDir%"=="" exit /B 1
xxxxx@FOR /F "delims=" %%i IN ('dir "%UniversalCRTSdkDir%include\" /b /ad-h /on')
DO @SET UCRTVersion=%%i
+@SET UCRTVersion=10.0.10240.0
@exit /B 0
:GetUniversalCRTSdkDirHelper64
@@ -299,7 +299,7 @@
)
)
@if "%UniversalCRTSdkDir%"=="" exit /B 1
xxxxx@FOR /F "delims=" %%i IN ('dir "%UniversalCRTSdkDir%include\" /b /ad-h /on')
DO @SET UCRTVersion=%%i
+@SET UCRTVersion=10.0.10240.0
@exit /B 0
@REM -----------------------------------------------------------------------

posted @ 2020-07-24 09:43  瓜蛋  阅读(362)  评论(0编辑  收藏  举报