Visual Studio 2022 有时候莫名其妙地在不能正常编译(可能是装多个 SDK 造成的),找不到 ctype.h 等头文件。在项目的 VC++ 目录定义中发现是 SDK 宏定义出错了,比如正常路径是 C:\Program Files (x86)\Windows Kits ,但变成了 C:\Program Files \Windows Kits 或 D:\Windows Kits 等。但是这些宏定义在 IDE 中是不能修改的,需要在系统注册表中修改。
缺 ctype.h 时 是 $(UCRTContentRoot) 的定义出错了,它是在 C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\uCRT.props 文件中被定义的:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UCRTContentRoot Condition="'$(UCRTContentRoot)' == ''">$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots@KitsRoot10)</UCRTContentRoot>
<UCRTContentRoot Condition="'$(UCRTContentRoot)' == ''">$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots@KitsRoot10)</UCRTContentRoot>
<TargetUniversalCRTVersion Condition="'$(TargetUniversalCRTVersion)' == ''">$(TargetPlatformVersion)</TargetUniversalCRTVersion>
<UniversalCRT_IncludePath>$(UCRTContentRoot)Include\$(TargetUniversalCRTVersion)\ucrt;</UniversalCRT_IncludePath>
<UniversalCRT_LibraryPath_x86>$(UCRTContentRoot)lib\$(TargetUniversalCRTVersion)\ucrt\x86;</UniversalCRT_LibraryPath_x86>
<UniversalCRT_LibraryPath_x64>$(UCRTContentRoot)lib\$(TargetUniversalCRTVersion)\ucrt\x64;</UniversalCRT_LibraryPath_x64>
<UniversalCRT_LibraryPath_arm>$(UCRTContentRoot)lib\$(TargetUniversalCRTVersion)\ucrt\arm;</UniversalCRT_LibraryPath_arm>
<UniversalCRT_LibraryPath_arm64>$(UCRTContentRoot)lib\$(TargetUniversalCRTVersion)\ucrt\arm64;</UniversalCRT_LibraryPath_arm64>
<UniversalCRT_SourcePath>$(UCRTContentRoot)Source\$(TargetUniversalCRTVersion)\ucrt;</UniversalCRT_SourcePath>
</PropertyGroup>
</Project>
可以看到,SDK 的根路径在注册表的 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots@KitsRoot10 或 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots@KitsRoot10 ,找到它并修改成正确的路径重启 VS 即可。
|