CMake error inability to find C and C++ compiler in Visual Studio 2019 when generator set to Visual Studio 16 2019

Hello,

I have a project that I have natively compiled/built under VS 2019 (CL.exe, MSBuild.exe via .vcxproj and .sln files). I am able to build this under CMake as well when the generator is set to Ninja.

However, when the generator is set to Visual Studio 16 2019 Win 64 via changes to CMakeSettings.json, I obtain the following error from the following line on my CML.txt

project (“CMakeProject” LANGUAGES C CXX)

The error is: No CMAKE_CXX_COMPILER could be found. (Same error appears for C compiler as well since I have specified languages as C and CXX)

The CMakeOutput.log file says:

The system is: Windows - 10.0.19045 - AMD64

I am unable to upload the CMakeError.log file as I am a new user. Could you please let me know how I could share that with the forum?

Could you please help fix this error? I would like to compare the .vcxproj created natively by Visual Studio IDE and compare that with the .vcxproj file CMake generates.

Thank you.


ETA: When the generator is set to Ninja, everything works without error and I am able to see the following in the Visual Studio IDE’s output box for CMake:

1> [CMake] – The C compiler identification is MSVC 19.29.30147.0
1> [CMake] – The CXX compiler identification is MSVC 19.29.30147.0

Any pastebin site or a Github Gist would be fine.

Below is the CMake output when I open a cmake project with default VSIDE setting of Ninja generator:

CMake generation started for configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\TryerGit\Insync\TryerGit@domain.com\GoogleDrive\research_programming\Setup Folder\VSIDE,VSCodePractice\cmake\trials\cmake\windows\install\x64-Debug" -DCMAKE_INSTALL_PREFIX:PATH="cmake/windows/install/x64-Debug"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\TryerGit\Insync\TryerGit@domain.com\GoogleDrive\research_programming\Setup Folder\VSIDE,VSCodePractice\cmake\trials" 2>&1"
1> Working directory: C:\Users\TryerGit\Insync\TryerGit@domain.com\GoogleDrive\research_programming\Setup Folder\VSIDE,VSCodePractice\cmake\trials\cmake\windows\build\x64-Debug
1> [CMake] -- The C compiler identification is MSVC 19.29.30151.0
1> [CMake] -- The CXX compiler identification is MSVC 19.29.30151.0
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: C:/Users/TryerGit/Insync/TryerGit@domain.com/GoogleDrive/research_programming/Setup Folder/VSIDE,VSCodePractice/cmake/trials/cmake/windows/build/x64-Debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.

Then, I change the generator to Visual Studio 16 2019 Win64. This is what gives the errors. The output is available at gist:c9bbed00423ec4360c199add61a91ae6 (github.com)

Thank you.

@brad.king Ideas?

The linked error log shows this error from MSBuild:

error MSB6003: The specified task executable "CL.exe" could not be run. System.IO.DirectoryNotFoundException: Could not find a part of the path '...'

The path to the build tree is pretty long and may be exceeding the limit of some VS tooling. It also contains characters like @ and , in path components.

1 Like

@ was indeed the offending part of the directory structure. Thank you! I am able to generate .vcxproj files now.