CMake configuring fails. "cl.exe is not able to compile a simple test program"
Asked Answered
C

6

31

I am trying to build a solution for MSVC++2010 using CMake. Since I installed Visual Studio 2012 that does not work anymore. CMake comes with the following error message: "The C compiler "C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe" is not able to compile a simple test program."

While searching a solution for my problem I found this topic (Cmake is Unable to Configure Project for Visual Studios 10 amd64) which though adresses my problem but the solution doesn't work for me.

Any help would be much appreciated.

Chaney answered 29/1, 2013 at 19:45 Comment(1)
I have had similar problems and ended up giving admin rights to devenv.exe. Note: by adding it to the properties of devenv.exe in Program FilesLonesome
S
14

I had the same problem on Win7.
What worked for me is what @Andre suggested in the comment:

  1. Right-Click->Properties on cl.exe in your VS install directory (the exact path appears in the CMake error);
  2. Choose the Compatibility Tab;
  3. Check "Run this program as administrator" in the "Privilege Level" box.
Stasiastasis answered 20/3, 2013 at 12:10 Comment(2)
This isn't working for me, please see my question #22393476. Also cl.exe (which is an XML file) doesn't have a compatibility tab, these should can only be done for cl, in the same folder.Caveator
@omgzor You have the "Hide extensions for known file types" option enabled. cl is actually cl.exe, and cl.exe is actually cl.exe.config. I recommend disabling this setting.Passel
L
11

I had the same problem. The above solution didn't work out for me. My problem was solved after looking into this post.

First, check if you have .NET 4.5 on your system. If you do, that is very likely causing the problem. Try either upgrading to VS2010 SP1 or downgrade .NET to 4.0

CAUSES:

This error appears because you have installed Visual C++ 2012 after you have actually installed Visual C++ 2010 in your system; another cause is because .net Framework 4.5 replace .net Framework 4.0; .net Framework corrupted files;

HOW TO SOLVE

Uninstall .NET Framework 4.5 from your system; then download .NET Framework 4.0 and install it; this should fix your problem;

Lorrimor answered 3/6, 2014 at 20:6 Comment(0)
C
7

I have met this problem, and I fixed by this way. You should run cmake in a console, command like

>vcvars32  (to set some system vars, C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvar32.bat)

>cmake .. -G"NMake Makefiles" (.. is your code folder) 

>nmake  (It will work well!)

You should do this jod in one console, don't open another.

Cisterna answered 14/4, 2016 at 15:46 Comment(0)
D
2

I encounter the excatly same problem. I solved by add a command before cmake

call "C:/Program Files (x86)/VC/vcvarsall.bat" amd64

The path of vcvarsall.bat and the architecture maybe different on your computer.

According to Usage of vcvarsall.bat, this command is to set up proper environment variable for command-line compilation.

Dump answered 11/4, 2018 at 9:57 Comment(1)
similar to Zheng SizeDump
S
0

For Visual Studio 2017 and using cmake, I was getting the below error message

-- Selecting Windows SDK version 10.0.17134.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.14.26433.0
-- The CXX compiler identification is MSVC 19.14.26433.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x64/cl.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x64/cl.exe"

  is not able to compile a simple test program.

And I resolved the issue by setting the build environment by running vcvars140.bat script (as shown below).

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\vsdevcmd\ext\vcvars> .\vcvars140.bat 
Selenium answered 23/2, 2021 at 12:42 Comment(0)
P
0

In order to use Microsoft Visual C++ compiler & linker on a shell, you’ve got to set some specific environmental variables, PATH, INCLUDE, and LIB.

Pharyngitis answered 17/12, 2022 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.