CMake 无法打开“ucrtd.lib”

2023-07-08 14:38:33 浏览数 (1)

CMake 无法打开“ucrtd.lib”

【解决方案1】: 正如this CMake 论坛中提到的,可能需要明确告诉 CMake 您安装了哪个特定的 Windows 版本。考虑到您安装了 10.0.17763.0 版本,包括以下定义会将 CMake 定向到该版本:

cmake -DCMAKE_SYSTEM_VERSION=10.0.17763.0 这里是docs 对应CMAKE_SYSTEM_VERSION。

【讨论】:

【解决方案2】: 如here 所述,如果您使用的是 VS2022,并且您安装的 Windows SDK 版本为 10.0.19041.0(在撰写本文时默认安装的是 VS2022),那么您可能遇到了这种情况。

这种情况下的解决方案是卸载该 SDK 版本并安装其他版本。

问题:用cmake编译时,显示No CMAKE_C_COMPLIER could be found。在cmakerror.log文件中显示"链接:错误 无法打开文件“ucrtd.lib”"

问题的原因是缺少某些组件。 解决方法:

重新打开VS2017安装包,选择修改

My problem is similar to this one: Problems generating solution for VS 2017 with CMake, but the solution doesn’t work for me.

When run cmake in Developer Command Prompt for VS 2017, I got the error (from CMakeError.log):

LINK : fatal error LNK1104: Cannot open file “ucrtd.lib” [E:ProjectsMy ProjectVSCMakeFiles3.14.4CompilerIdCCompilerIdC.vcxproj]

But the file ucrtd.lib is located in the Windows Kits folder.

echo %LIB%

D:Program Files (x86)Microsoft Visual Studio 2017 CommunityVCToolsMSVC14.16.27023libx86;C:Program Files (x86)Windows KitsNETFXSDK4.6.1libumx86;C:Program Files (x86)Windows Kits10lib10.0.17763.0ucrtx86;C:Program Files(x86)Windows Kits10lib10.0.17763.0umx86;

dir “C:Program Files (x86)Windows Kits10lib10.0.17763.0ucrtx86” /w /b

libucrt.lib libucrtd.lib ucrt.lib ucrtd.lib

And I also try to manually run the build command listed in the CMakeError.log, it succeeds, no error.

CL.exe /c /nologo /W0 /WX- /diagnostics:classic /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug" /Fd"Debugvc141.pdb" /Gd /TC /analyze- /FC /errorReport:queue CMakeCCompilerId.c

link.exe /ERRORREPORT:QUEUE /OUT:“.CompilerIdC.exe” /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /manifest:embed /PDB:“.CompilerIdC.pdb” /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:“.CompilerIdC.lib” /MACHINE:X86 /SAFESEH DebugCMakeCCompilerId.obj

So it seems like cmake didn’t recognize the environment variables, or did I miss some important steps?

cmake version is 3.14.4 visual studio version is 15.9.7

代码语言:javascript复制
Make sure HKLMSoftwareMicrosoftWindows KitsInstalled Roots@KitsRoot10 is set to:

C:Program Files (x86)Windows Kits10

and NOT:

C:Program FilesWindows Kits10

Full Explanation On the LNK1104 error page, there’s a relevant section titled, “Updated Windows SDK libraries”, that reads:

This error can occur when the Visual Studio path to the Windows SDK is out of date. It may happen if you install a newer Windows SDK independently of the Visual Studio installer. To fix it in the IDE, update the paths specified in the VC Directories property page. Set the version in the path to match the new SDK. If you use the Developer Command Prompt, update the batch file that initializes the environment variables with the new SDK paths. This problem can be avoided by using the Visual Studio installer to install updated SDKs.

Given this, the reasonable thing to do would seem to be to verify that the “Macro” pointing to the path containing the ucrt library files is in use.

enter image description here

However, this may not be enough. That Macro may be wrong.

enter image description here

This message from a Microsoft engineer says that some older Windows Kits improperly set the path to the ucrt. In these kits, they use the 64-bit program files path (“Program Files”) instead of the 32-bit path (“Program Files (x86)”). However, during installation, if the path is already set, then it will not be updated by a subsequent Windows SDK installer.

So it’s possible that your system will have the environment variable defined to the wrong value, resulting in Visual Studio failing to find the relevant library.

In that case, the Microsoft engineer’s recommendation was to either update the offending registry value, or delete it then reinstall the Windows SDK.

Hey Alexander,

I’ve spoken to the Windows SDK team about this. In general, kit installers are not supposed to set ‘HKLMSoftwareMicrosoftWindows KitsInstalled Roots@KitsRoot10’ to C:Program FilesWindows Kits10, it is always supposed to point to C:Program Files (x86)Windows Kits10. However, there are Kits out there that make this mistake, and the registry key is never updated if it already exists prior to any kit installation. I believe whichever windows kit you’ve installed on that system first had this issue.

That said, these issues will never go away entirely since there will always be kits and machines floating around with this issue. I’ve updated ucrt.props to be more defensive about this by checking the Wow6432Node version first (which has not had this issue historically), and only if that isn’t present to fall back to the usual registry key.

This fix will be present in the next released Windows 10 SDK. In the meantime, I recommend either deleting that reg key and reinstalling the Windows 10 SDK, or simply directly modifying HKLMSoftwareMicrosoftWindows KitsInstalled Roots@KitsRoot10 to point to C:Program Files (x86)Windows Kits10 (the same effects of the deleting the reg key and reinstalling, but less error prone).

Hope this helps!

Steve Wishnousky Senior Software Engineer - Visual C Libraries stwish@microsoft.com

(quoted here because of concerns about the long-term availability of the message at the link)

=================== As described here, if you’re on VS2022 and your installed Windows SDK is version 10.0.19041.0 (which is what installs with VS2022 as the default as of this writing), then you may have run into this.

The solution in that case is to uninstall that SDK version and install a different one.

代码语言:javascript复制
As mentioned in this CMake forum, it may be necessary to explicitly tell CMake which specific Windows version you have installed. Considering you have version 10.0.17763.0 installed, including the following definition will direct CMake to that version:

cmake -DCMAKE_SYSTEM_VERSION=10.0.17763.0
Here are the docs for CMAKE_SYSTEM_VERSION.

Share
Follow
代码语言:javascript复制
HKEY_LOCAL_MACHINESOFTWAREWOW6432NodeMicrosoftWindows KitsInstalled Roots
代码语言:javascript复制
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows KitsInstalled Roots

这个两个地方都要修改

代码语言:javascript复制
C:Program Files (x86)Windows Kits10

注意后面有

0 人点赞