Windows configure error when using the command line: "The C/CXX compiler identification is unknown.."

I fail to use the command line to configure, reporting errors as “The C compiler identification is unknown and The CXX compiler identification is unknown”.
image

But for the same project, it is successful when using the cmake-gui. My cmake version is 3.20.4.
report information like:
Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
The C compiler identification is MSVC 19.16.27045.0
The CXX compiler identification is MSVC 19.16.27045.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: D:/Program Files/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: D:/Program Files/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
operation system is Windows-10.0.19042
Found OpenMP_C: -openmp (found version “2.0”)
Found OpenMP_CXX: -openmp (found version “2.0”)
Found OpenMP: TRUE (found version “2.0”)

Anyone could help? I don’t know why there is a difference in my vs2017 build and how to solve it in command-line way.

Guessing: The cmake-gui chooses the 32bit (host and target) version of the compiler. You choose the host=64bit version with CLI

When you use the GUI it appears to be using the Hostx86 tools not Hostx64. Did the command line version work when not specifying the toolset with -T.

It still has the same prompt error when removing the “-T” option.

I try to add the x86 compiler path “D:\Program Files\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86” to the system environment path, it still has the same error.

Actually, I don’t know how the cmake-gui works and why it chooses the x86/32bits option. And how it detects the complier information of:

The C compiler identification is MSVC 19.16.27045.0
The CXX compiler identification is MSVC 19.16.27045.0

I have local search results for the cl.exe as shown below…

Usually this means that something like the SDK isn’t installed. Does the toolchain work outside of CMake?

I tested a simple cpp file using the shell of MSVC tool, the cl build was successful.

While I try the cmake command in the same shell, it prompt the same error…
– Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
– 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.

Hello @StevenWang we ended up finding a solution over on this discourse. Try temporarily minimizing your PATH variable to see if that helps as shown in that thread.

Yes, minimizing the PATH in temp can solve this CLI issue!

Thank you and everyone who helped me so much.

Make sure to mark your question as answered btw.