4

I am calling cmake -G "NMake Makefiles" from a Microsoft Visual C++ 2010 x64 command prompt. The C compiler identification is correct, but the CXX compiler identification not.

I am really confused, because it has worked before, but I could not determine what changed (Windows update?) and raised this issue. So I am searching for the root for this problem.

How does CMake find the cxx compiler (on Windows: cl.exe) and maybe how do I change this behavior? (Setting CMAKE_CXX_COMPILER seems not to have any effect.)

Here the strange output of CMake:

The C compiler identification is MSVC 16.0.40219.1
The CXX compiler identification is unknown
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC  /bin/amd64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/amd64/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/cl.exe
CMake Error: your CXX compiler: "C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/cl.exe" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/cl.exe -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/x86_amd64/cl.exe" is not able to compile a simple test program.

Visual Studio 9 is not installed on this machine (Where on earth is the path C:/Program Files (x86)/Microsoft Visual Studio 9.0 coming from? It does not exit on this machine, and I did not type it anywhere in CMake.)

CMake (output above) was called from a Visual Studio command prompt. This call reproduces this issue:

call "%VS100COMNTOOLS%"\..\..\VC\bin\amd64\vcvars64.bat 
cmake -G "NMake Makefiles" C:\base_repos\free

Visual Studio 2010 Ultimate (SP1 installed)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
550
  • 1,070
  • 1
  • 13
  • 28
  • Is it working with VS2010 generator? – Peter Petrik May 06 '14 at 06:10
  • Yes. -G "Visual Studio 10" and "Visual Studio 10 Win 64" are working properly. (Note that this problem with CXX identification occures for -G "NMake Makefiles" on both: x86 and x64 command prompt.) I figured out that forcing a compiler (setting CMAKE_CXX_COMPILER_FORCED=ON) skips the test build-project and allows to manually set the CMAKE_CXX_COMPILER. But that is only a workaround. The autofind of cxx compiler is still open. – 550 May 06 '14 at 08:36
  • 1
    https://cmake.org/pipermail/cmake/2013-March/053819.html ("[CMake] How does cmake find its compiler?"). "If you set the CC (or CXX respectively) environment variable, it will use this compiler. This is the recommended way how to point cmake to a specific compiler." – starball Jul 18 '22 at 18:57
  • edit: if you don't want to set an environment variable, which will become a default for all cmake projects configured under that environment, you can set the following cache variables on the commandline: `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER`. Ex. `cmake -S ... -B ... -D CMAKE_CXX_COMPILER=g++-11`. – starball Aug 12 '22 at 06:02

0 Answers0