CMake Compiler Error on Windows Using Visual Studio 2017

If you're like me, you've run into the following set of errors when trying to use CMake on Windows and especially when trying to compile Python code:

-- Building for: NMake Makefiles
-- The CXX compiler identification is unknown
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:131 (project):
  The CMAKE_CXX_COMPILER:

    cl

  is not a full path and was not found in the PATH.

  To use the NMake generator with Visual C++, cmake must be run from a shell
  that can use the compiler cl from the command line.  This environment is
  unable to invoke the cl compiler.  To fix this problem, run cmake from the
  Visual Studio Command Prompt (vcvarsall.bat).

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:131 (project):
  The CMAKE_C_COMPILER:

    cl

  is not a full path and was not found in the PATH.

  To use the NMake generator with Visual C++, cmake must be run from a shell
  that can use the compiler cl from the command line.  This environment is
  unable to invoke the cl compiler.  To fix this problem, run cmake from the
  Visual Studio Command Prompt (vcvarsall.bat).

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.

Read on for instructions on how to get past this error...

The solution is to modify the installation of Visual Studio 2017 and install a specific individual component.

  1. Go to Add or Remove Programs and Modify your Visual Studio 2017 installation
  2. Click the Individual Components heading at the top
  3. Under Compilers, build tools, and runtimes check the Visual C++ tools for CMake (see image below)
    • Allow it to include any other necessary dependency items for CMake tools
  4. Click the Modify button to have it update the installation
  5. When installation is done, if you have a command prompt shell open still you will want to restart it.
  6. Try your CMake command again. It should work!

Modify Visual Studio 2017 to include CMake Tools

Tag: microsoft visual studio python cmake compiler

Comments (0)


The Grim Admin
https://www.grimadmin.com/article.php/cmake-compiler-error-on-windows-using-visual-studio-2017