Compiler identification problem (VS2022)

I have installed VS2022 and Windows SDK. There is VS2017 previously installed.

I am running cmake-gui (3.22.2) on some project and try to configure it. I can’t get past the compiler identification.

When I examined the CMakeError.log file there is this error:
LINK : fatal error LNK1104: cannot open file ‘ucrtd.lib’

This library comes from the installed Windows SDK. It seems there is an annoying bug in VS2022 which doesn’t add all required library folders into the compiler LIBPATH. This happens even in the IDE but there I am able to add missing folders in the project settings.

How to configure library search folder for the compiler identification step? I tried to set CMAKE_EXE_LINKER_FLAGS=/LIBPATH:path-to-missing-lib-folder but it didn’t help. Maybe this variable is not used for the compiler identification step.

Any idea how to fix this?

Ignore the error log for now. What does the console output say?

Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
The C compiler identification is unknown
The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:2 (project):
No CMAKE_CXX_COMPILER could be found.

Configuring incomplete, errors occurred!
See also “C:/work/opendrive-convertor/work22/CMakeFiles/CMakeOutput.log”.
See also “C:/work/opendrive-convertor/work22/CMakeFiles/CMakeError.log”.

Never mind that wasn’t actually that helpful of advice I gave

Here is what I found on the web:

Otherwise try re-refreshing your visual studio installation and ensure you have all the necessary components for building a C++ project.

Try using the repair option.

BTW does this issue happen for both VS2017/VS2022 ?

If that still doesn’t help at all provide a complete log of what’s happening.

cd your_project

# Delete your old build folder
rm build

# Make a new vs solution, and redirect all output to a file.
cmake -S . -B build --trace-expand *> log.txt

Today I installed a new version of Windows SDK through VS installer. Everything started working.

I think there is a problem with SDK 10.0.19041.0 which is the default SDK for VS 2022. When using this SDK compiler doesn’t get complete library paths so it fails when looking for ucrtd.lib. I can see that $(WindowsSDK_LibraryPath_x64) misses ucrt directory. Installation of new SDK fixes this. It looks like a msbuild’s internal SDK-detection problem.

2 Likes

Good to hear you could fix your problem by installing a new version of the SDK :+1:

If you have some time consider responding to this stack overflow question since the question is so similar and your answer is much better:

visual studio - CMake cannot open “ucrtd.lib” - Stack Overflow

Also consider filing an issue with the VS team.