Search code examples
c++visual-studiovisual-c++cmakevisual-studio-2017

Problems generating solution for VS 2017 with CMake


So I installed Visual Studio 2017 yesterday. I also installed CMake 3.7.2 which supports VS 2017.

My VS installation is with the Game development with C++ workflow + a few other components:

individual_components

I've also added the CMake stuff (but I don't think I even needed it - since I'm using CMake as a standalone tool to just generate the VS solutions) and MSBuild (I had msbuild.exe even before adding that component - so not sure what exactly does that additional component do).

With VS 2015 I was able to just run cmake . from a normal command prompt for a solution.

With VS 2017 the workflow changes - I've read this post from Microsoft.

So I tried the following:

  • I opened the Developer Command Prompt for VS 2017 and from it I ran cmake . -G "NMake Makefiles". Then running cmake --build . compiled everything properly.
  • When I tried the following in the prompt: cmake . -G "Visual Studio 15 2017 Win64" to force the creation of a solution I got the following errors:

    -- The C compiler identification is unknown
    -- The CXX compiler identification is unknown
    CMake Error at CMakeLists.txt:3 (project):
      No CMAKE_C_COMPILER could be found.
    CMake Error at CMakeLists.txt:3 (project):
      No CMAKE_CXX_COMPILER could be found.
    -- Configuring incomplete, errors occurred!
    

I also tried setting up the environment using vswhere.exe and running vcvarsall.bat like this:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64

and again I could only generate NMake files and not a solution.

So how can I get a solution?

And why does cl.exe report Version 19.10.25017 when it's in VC\Tools\MSVC\14.10.25017\bin?


Solution

  • Turning my comments into an answer

    The error -- The CXX compiler identification is unknown - No CMAKE_CXX_COMPILER could be found. basically means that CMake wasn't able to compile a simple test program (which it always does as part of identifying/validating the compiler).

    You can take a look into CMakeFiles\CMakeError.log (relative to your binary output directory), the error reason should be in there.

    Two possible reasons I came across so far:

    1. Missing administrator rights. You can try running this again from a shell that has administrative rights to crosscheck if your Visual Studio was setup with the need for administrator rights.

    2. Missing Windows SDK. Verify your SDK installation e.g. check that you have any Resource Compiler installed. It should be in a path similar to:

      C:\Program Files (x86)\Microsoft SDKs\Windows\v[some version]\bin\RC.Exe
      

    Visual Studio 2017 Installation

    Please note the Visual Studio may not install all necessary C++ packages even when you select one of the C++ pre-defined packages (as I have e.g. used Desktop development with C++ and then added more packages under the Individual Components tab).

    Here is which selection worked for me (VS2017 Community Edition, Windows 10):

    enter image description here

    If you have projects using MFC/ATL libraries you need to add it under SDKs, libraries, and frameworks subcategory:

    enter image description here

    References