141

After installing Visual Studio 2015 and running CMake on a previous project, CMake errors stating that it could not find the C compiler.

The C compiler identification is unknown
The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:4 (PROJECT):
  No CMAKE_C_COMPILER could be found.

CMake Error at CMakeLists.txt:4 (PROJECT):
  No CMAKE_CXX_COMPILER could be found.

I went searching for cl.exe in the Visual Studio folder,C:\Program Files\Microsoft Visual Studio 14.0, and could not find it.

How do I set up CMake to work on Windows with Visual Studio 2015?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Asher
  • 2,891
  • 3
  • 13
  • 12
  • 1
    Maybe the installation path of 2015 is not what CMake expect? Which version of CMake do you use? Also, I don't know about the Windows version of CMake, but it might be possible that CMake looks in the `PATH` to find the program it needs, so if it's not updated then it can't find the compiler. – Some programmer dude Jul 24 '15 at 20:38
  • 1
    I am using cmake version 3.2.3 which claims to have support for Visual Studio 2015 – Asher Jul 24 '15 at 20:41
  • 1
    Use version 3.2.x, I met this problem when I install Cmake before VS2015, so reinstall cmake fix this for me – Andiana Jan 07 '16 at 00:56
  • Sometimes you just forget to reboot your computer, or don't want to after a Visual Studio installation or update. In that case, CMake won't find your compiler. – Noki Aug 19 '18 at 09:32
  • Encountered this on VS 2022. Found [this](https://stackoverflow.com/a/72297058/6625422) solution. Changing the Registry `HKLM\Software\Microsoft\Windows Kits\Installed Roots@KitsRoot10` fixed it – Henry Fung Aug 11 '22 at 02:08

31 Answers31

132

I have found the solution. While the Visual Studio IDE installed successfully it did not install any build tools and therefore did not install the C++ compiler.

By attempting to manually create a C++ project in the Visual Studio 2015 GUI I was able to prompt it to download the C++ packages. CMake was then able to find the compiler without any difficulty.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Asher
  • 2,891
  • 3
  • 13
  • 12
  • 2
    Cool, this answer gave me the clue. I use my VS2015 ISO to install the C++ components and problem solved. – Peter Liang Mar 09 '16 at 03:31
  • I also installed using the VS2015 ISO and it installed the basic vb/c# parts only. Had to launch ISO again to modify and install other c++ stuff. – Abhinav Gauniyal Apr 05 '16 at 08:52
  • 2
    Exactly which packages/components/stuff did you guys install? I created a Visual C++ / Win32Project, and it installed two components, and ran OK inside VS, but cmake still complained as before. Thanks. -S – ssimm Jun 16 '16 at 07:37
  • That's very nice! – user2434741 Mar 27 '18 at 10:20
  • 2
    This has worked with vs 2017 as well - what a weird thing! Thanks for the tip, mate! – Steve Horvath May 29 '18 at 05:54
  • After following this solution, I found that the error occurred as an indirect result of deleting my TEMP and TMP environment variables. For others that find this, check and make sure your "TEMP" and "TMP" exist (Mine point to "%USERPROFILE%\AppData\Local\Temp"). I also restarted my computer for these changes to affect all programs. – cdgraham Dec 06 '18 at 18:59
  • Also remember to delete your build folder after getting the build tools installed, otherwise the CMake won't try to find the newly installed compiler – Ou Tsei Jul 03 '23 at 12:12
35

Here is the solution that worked for me:

  1. Open Visual Studio command prompt tool (as an administrator). On windows 10 it might be called 'Developer command prompt'.
  2. Navigate to where you have the CMake executable
  3. Run Cmake.exe
  4. Proceed as usual to select build and source folder
  5. Select the appropriate Visual Studio compiler and hit the configure button

Hopefully it should run without problems.

Roelant
  • 4,508
  • 1
  • 32
  • 62
Fortune
  • 1,243
  • 2
  • 19
  • 22
  • @Mavie Am glad to have helped – Fortune Oct 01 '16 at 17:15
  • 3
    I don't think that you need to run VS Command prompt as administrator. But running the VS command promt does put everything cmake is looking for on the path. Depending on how you installed CMake (whether you put it on the path) you can also navigate to your build directory and run `cmake ..` from there. Upvoted anyway, because the git-bash terminal for example doesn't autmatically put everything on its path. This helped me! – hetepeperfan Oct 18 '16 at 06:33
  • 1
    This seems more like a workaround than a solution, since normally, the IDE generators don't need the various environment variables as found in the dev command prompts set (you'd only need that if you were using a makefile generator or similar, such as Ninja) – Ryan Pavlik Nov 21 '17 at 10:30
  • 2
    update: on Windows 10 this is called the [Developer Command Prompt](https://learn.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) – Mattijs Jun 29 '18 at 13:21
  • 2
    Very strange explanation: 1: It's not called VS Studio command prompt 2: "navigate", you mean using the "cd" command? 3: You mean, run cmake-gui? As you say in step 5 to "click" on a button 4: Proceed?? you mean fill in? 5: On the dropdown box in the configure window, I can select the VS compiler, but still the C & C++ compilers are unknown... – jaques-sam Aug 21 '18 at 13:49
  • 1
    Btw, just type in search cmake and you'll find the cmake-gui – jaques-sam Aug 21 '18 at 14:38
32

I looked in CMakeError.log file and found an error about cannot run 'rc.exe'

I searched and found this answer to copy RC.Exe and RcDll.Dll from the Microsoft SDKs bin to the VC bin, and then CMake worked.


Edit: The top answer to another question suggests that it's a PATH issue, so it could be enough to ensure the Microsoft SDK bin is in your PATH.

Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
  • yes, it's helpful to read the real error in the `CMakeError.log`, in my case, it's `LINK : fatal error LNK1104: cannot open file 'ucrtd.lib'`, which is fixed by https://stackoverflow.com/a/71418520 – Felix F Xu May 18 '23 at 06:52
17

Those stumbling with this on Visual Studio 2017: there is a feature related to CMake that needs to be selected and installed together with the relevant compiler toolsets. See the screenshot below.

Visaul C++ tools for CMake must be installed

Vadim Berman
  • 1,932
  • 1
  • 20
  • 39
16

Make sure you are using the correct version of Visual Studio in the generator. I had incorrectly selected Visual Studio 15 when Visual Studio 14 installed.

  • 3
    This was my problem too. It is confusing because Visual Studios 2015 is Version 14! – Paul Wintz Feb 02 '17 at 21:21
  • 4
    Note that you might need to delete your cache in order to change the version of VS. To do this, click File>Delete Cache. – Paul Wintz Feb 02 '17 at 21:32
  • 1
    This helped ... versioning at its best! – Noel Widmer Mar 28 '17 at 19:03
  • arrrrg, @PaulWintz thank you for that reminder. I think in my case I ran cmake with a clean cmake cache but while VisualStudio was waiting for me to restart the computer in order to complete a VS update, and then cmake cleverly cached the bad situation. – orion elenzil Apr 21 '20 at 21:26
10

If none of the above solutions worked, then stop and do a sanity check.

I got burned using the wrong -G <config> string and it gave me this misleading error.

First, run from the VS Command Prompt not the regular command prompt. You can find it in Start Menu -> Visual Studio 2015 -> MSBuild Command Prompt for VS2015 This sets up all the correct paths to VS tools, etc.

Now see what generators are available from cmake...

cmake -help

...<snip>...
The following generators are available on this platform:
  Visual Studio 15 [arch]      = Generates Visual Studio 15 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
                                 Optional [arch] can be "Win64" or "ARM".
  Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
                                 Optional [arch] can be "Win64" or "IA64".
...

Then chose the appropriate string with the [arch] added.

mkdir _build
cd _build
cmake .. -G "Visual Studio 15 Win64"

Running cmake in a subdirectory makes it easier to do a 'clean' since you can just delete everything in that directory.

I upgraded to Visual Studio 15 but wasn't paying attention and was trying to generate for 2012.

Martin Valgur
  • 5,793
  • 1
  • 33
  • 45
TrophyGeek
  • 5,902
  • 2
  • 36
  • 33
8

For me, I checked the CMakeError.log file and found:

[...] error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".

This is despite using Visual Studio 2017 on Windows 7. So it appears that CMake is trying to build its detection project with the Windows 8.1 SDK.

I used the Visual Studio installer to add that component and now CMake is happy as a clam.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
chowey
  • 9,138
  • 6
  • 54
  • 84
5

Menu → Visual Studio 2015 → MSBuild Command Prompt for Visual Studio 2015. Then CMake can find cl.exe.

set PATH="c:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64\";%PATH%

Change the upper path to where your Windows SDK is installed.

CMake can find rc.exe.

cd to the path of CMakeLists.txt and do:

md .build
cd .build
cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release
cmake --build .

The param after -G should be fetched by CMake. Use --help; you may or may not have the generator.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alen Wesker
  • 237
  • 3
  • 6
  • When you have msvc 2015 and 2017 installed, and trying to build with msvc 2015, it will autodetect the 10.0 SDK when running the vs2015 command-prompt. You can specify the SDK-version by modifying the "VS2015 x64 Native Tools Command Prompt" to force the 8.1 sdk by adding at to the end of the commandline-parameter like this; "%comspec% /k ""C:\Program Files (x86)\msdev2015\VC\vcvarsall.bat"" amd64 8.1" – kalmiya Aug 20 '18 at 22:38
  • Do I have to install 'MSBuild Command Prompt for Visual Studio 2015' seperatetly? I installed msvc 2017 but command prompt for visual studio is not there. – meen Nov 17 '18 at 20:36
2

I ran into the same issue and fixed it by relaunching the Visual Studio Install and checking the following option:

Windows and Web Development / Universal Windows App Development Tools / Windows 10 SDK

It contains the standard C++ headers used in most applications and therefore it is often necessary to install it as well.

Ben
  • 2,314
  • 1
  • 19
  • 36
2

I had this issue under Windows 10 when using Visual Studio 2015 Professional, while Visual Studio 2015 Express worked! Under Windows 7, both Visual Studio versions used to work.

New projects created from the Visual Studio 2015 Professional IDE successfully compile, but CMake would fail to find the compiler reporting:

The C compiler identification is unknown
The CXX compiler identification is unknown

I upgraded CMake from 3.4.1 to 3.11.4, and now the problem is gone.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jpo38
  • 20,821
  • 10
  • 70
  • 151
1

If you are on Visual Studio 2017 you need at least CMake 3.8!

Lars Bilke
  • 4,940
  • 6
  • 45
  • 63
1

I had a similar problem with the Visual Studio 2017 project generated through CMake. Some of the packages were missing while installing Visual Studio in Desktop development with C++. See snapshot:

Visual Studio 2017 Packages:

Visual Studio2017 Packages

Also, upgrade CMake to the latest version.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
vinodsaluja
  • 573
  • 6
  • 15
1

Checking CMakeErrors.log in CMakeFiles returned:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\x64\PlatformToolsets\v140_xp\Toolset.targets(36,5): warning MSB8003: Could not find WindowsSdkDir_71A variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.

The error means that the build tools for XP (v140_xp) are not installed. To fix it I installed the proper feature in Visual Studio 2019 installer under Individual Components tab:

enter image description here

Nathan Moinvaziri
  • 5,506
  • 4
  • 29
  • 30
1

I was running old cmake version (i.e. 3.8) and I'm using visual studio 16 - 2019. After updating my cmake version, it did detect the compiler.

CroCo
  • 5,531
  • 9
  • 56
  • 88
0

In my case I could see in the CMakeError.log that CMake could not find the Windows SDK (MSB8003: Could not find WindowsSDKDir variable from the registry).

The version can be specified on the commandline on the first CMake run using:

-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=

I got further after setting that, but I hit more issues later (so I assume my environment is messed up somehow), but maybe it will help someone with this issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zitrax
  • 19,036
  • 20
  • 88
  • 110
0

A couple of tips:

  • Try to set the path manually by checking 'advanced' and modifying CMAKE_LINKER and CMAKE_MAKE_PROGRAM
  • Delete the cache - in the CMake with GUI go to: File → Delete Cache.

My problem was a combination of previously stated: I have set the compiler version to 15 instead of 14 and when corrected, I had to delete the cache.

I also started the Visual Studio command prompt as an administrator and from there I ran the cmake-gui.exe

Then everything worked as it was supposed to.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rarach
  • 1
  • 1
0

In my case the issue was that the parent project, which is including googletest via

add_subdirectory(gtest_dir)

was defined as

PROJECT( projname CXX )

Somehow, CMake does not recognize

PROJECT(sub_project_name CXX C)

since the C compiler is not set in the parent.

I solved the issue by using

PROJECT( projname CXX C)

in my main CMakeLists.txt file.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mojovski
  • 581
  • 7
  • 21
0

In my case there was an environment variable set which was the reason for this error. The problem was solved after deleting cxx_flags from the environment variables.

Starger
  • 21
  • 1
  • 6
0

This might be another solution for those with the latest Windows 10 creator version:

Stack Overflow post Fatal error LNK1104: cannot open file 'gdi32.lib'

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alan
  • 1,582
  • 1
  • 13
  • 11
0

None of the previous solutions worked for me. However I noticed that although I installed Visual Studio version 15 (not to be confused with Visual Studio 2015) the directory created on my computer was for Visual Studio 14.

When I specified Visual Studio 14 when I pressed the configuration button it worked.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gamaliel
  • 11
  • 1
  • The version numbering for Visual Studio is just... odd. Visual Studio 14 is in reality Visual Studio 2015, there is no Visual Studio 2014. See trophygeek's answer https://stackoverflow.com/a/40332976/1319284 – kutschkem May 07 '18 at 10:39
0

I got this problem with CMake 3.12.1, after an update of Visual Studio 2017. I simply re-ran CMake and it worked.

0xF
  • 3,214
  • 1
  • 25
  • 29
0

i found this sollution at stackoverflow and i work for me although not working other sollutions if you have a windows 10 OS, doing the following steps will fix the problem:

1) go to C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin

2) then copy RC.exe and RcDll from this file

3) go to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin and paste the two files you have copied into it.

thats all i hope it is helpful...

0

Look in the Cmakelists.txt if you find ARM you need to install C++ for ARM and as well vcvarsall.bat use for ARM bin folder.

It's these packages:

C++ Universal Windows Platform for ARM64 "Not Required"

Visual C++ Compilers and libraries for ARM "Not Required"

Visual C++ Compilers and libraries for ARM64 "Very Likely Required"

Required for finding Threads on ARM 
enable_language(C) 
enable_language(CXX)

Then the problems might disappear:

No CMAKE_C_COMPILER could be found.

No CMAKE_CXX_COMPILER could be found.

If above does not resolve your problem?

Optionally you can remove the options C and CXX in cmakelists.txt by setting # infront of where the enable_language(C) is. And avoid Android ARM processor compilation.

Dealazer
  • 59
  • 4
0

Resolved by adding the missing component Modify->continue add as follow Fix

Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
0

I had a related problem: the Visual C++ generators were not even on the list when running cmake --help.

I ran where cmake in console and found that cygwin also provides its own cmake.exe file, which was being used. Changing the order of directories in PATH fixed the problem.

stgatilov
  • 5,333
  • 31
  • 54
0

I had this issue with CMake GUI and the VS 21019 Community Edition. I think I may have installed CMake before Visual Studio - certainly after I updated CMake 3.15.2 to 3.15.3 the problem went away.

0

Check name folder too long or not.

0

This question is old, but none of the solutions here were working for me. I'm using Visual Studio 2019, and in my case, C++ compilation was working but just broke one day.

However, I noticed that there was an update ready to be installed in the Visual Studio Installer.

After installing that update, rebooting my computer, and relaunching Visual Studio, all of the C++ CMake problems disappeared. I'm not quite sure why this fixed it, and I can only speculate, but I can only assume that one of two things occurred. Either installing that update fixed a broken installation, or the update was quietly downloaded and prepared in the background, breaking things in the process.

RomanPort
  • 81
  • 1
  • 6
0

I met the same issue in VSCode Cmake extension, i solve it by check following two options: enter image description here enter image description here

In the end, click [Scan for kits]

Wade Wang
  • 536
  • 6
  • 11
-2

cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug "-DCMAKE_C_COMPILER:FILEPATH=C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gcc.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe" -Hc:/code -Bc:/code/build -G "MinGW Makefiles"

Erfan
  • 1
-3

Because CMake is not able to find your Visual Studio compiler. Start any project which will download the required compilers and CMake must be able to find it then.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kushal
  • 1
  • 1