CMake with Microsoft Visual C++ Build Tools - c++

EDIT:
Having posted this to their issue tracker and stepped through it with some CMake devs, this actually isn't a CMake problem. Something is broken with my MSBuild installation that causes it to return the "The operation completed successfully." error. Still no resolution on the issue overall, but this narrows down the potential causes.
I'm trying to build a CMake project on Windows using the MS Visual C++ Build Tools 2015 (note: not full Visual Studio). CMake, however, is apparently unable to find cl.exe
cmake ..
-- Building for: Visual Studio 14 2015
-- 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 suspect this is because CMake is expecting to find the compiler in with the Visual Studio installation but perhaps the standalone build tools install it in a different location? Is it possible to configure CMake to look elsewhere for the compiler?
EDIT: To head this possibility off at the pass, cl.exe is definitely installed. When I open the Visual C++ shell (adds the tools to the path) cl.exe outputs:
cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
And that is the same environment I'm running cmake .. from so cl.exe is definitely on the PATH for discovery by CMake.
EDIT 2: Looking at the CMakeError.log file I see a couple variants of the following
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 4/14/2017 11:58:13 AM.
Project "E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "Debug\".
Creating directory "Debug\CompilerIdCXX.tlog\".
InitializeBuildStatus:
Creating "Debug\CompilerIdCXX.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:queue CMakeCXXCompilerId.cpp
TRACKER : error TRK0002: Failed to execute command: ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe" #C:\Users\<user>\AppData\Local\Temp\tmpa0925a9f05d5426d82afdcee8d722031.rsp". The operation completed successfully. [E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(ClCompile target) ->
TRACKER : error TRK0002: Failed to execute command: ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe" #C:\Users\<user>\AppData\Local\Temp\tmpa0925a9f05d5426d82afdcee8d722031.rsp". The operation completed successfully. [E:\<project_dir>\build\CMakeFiles\3.8.0-rc4\CompilerIdCXX\CompilerIdCXX.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.21
This looks like some kind of output compatibility issue, especially the "ERROR: The operation completed successfully." lines. I'm using CMake 3.8.0-rc4 and the Visual C++ 2015 Build Tools. Any ideas?
EDIT 3:
I thought that upgrading from 3.8.0-rc4 to 3.8.0 might fix it, but no avail. I also considered that I was using 64bit CMake trying to build a 32 bit program so I changed that as well. No luck yet.
EDIT 4:
Also, for the record, this does build with CMake on a PC with full VS 2015 installed.

I'm not sure I bring a solution to your The operation completed successfully problem, but I was able to compile a [big] real-life project using cmake 3.8.1 and C++2015 BuildTools.
The trick is simply to use the "VS2015 x64 Native Tools Command Prompt" (or x86). You either call cmake using this prompt, or you call this prompt from your normal prompt and it will set your path properly.
REM Set up the include/lib paths of Visual Studio
call "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" amd64
cd to_build_dir
REM Call cmake with the right parameters
"C:\Program Files\CMake\bin\cmake.exe" .......
REM Build the XYZ project
MSBuild.exe SOLUTION_FILE.sln /t:XYZ .......
As I wrote, I'm not sure it will fix your error because I wasn't able to reproduce it. However, I know that my project compile only when I use the right prompt. When I'm not using it, I get some error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Related

VS2017 + ICC 19.0: Failed to run MSBuild command

I am trying to build a C++ project using Visual Studio 2017 on top of the ICC 19.0 compiler.
This is the command I try to execute:
cmake -G "Visual Studio 15 2017 Win64" -T "Intel C++ Compiler 19.0" ..
This is the error I always get:
CMake Error at CMakeLists.txt:17 (project):
Failed to run MSBuild command:
C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/MSBuild/15.0/Bin/MSBuild.exe
to get the value of VCTargetsPath:
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2019-12-24 15:19:24.
Project "C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Redirect.14.props(47,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.cpp.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. [C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj]
Done Building Project "C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj" (default target) (1) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Redirect.14.props(47,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.cpp.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. [C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.08
Exit code: 1
-- Configuring incomplete, errors occurred!
I do have VS2017 build tools installed — and reinstalled several times, for that matter.
What am I doing wrong?
Why is it trying to use VS2015 build tools that I don`t even have?
[UPD:] The result is the same even when I execute this command from x64 Native Tools Command Prompt for VS2017.
Please check whether file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.cpp.props" is exist.
If the project is ported from VS2015, Please check VisualStudioVersion parameter in your project file (.csproj/.vbproj), such as "C:\Users\user001\Desktop\myproject\build\CMakeFiles\3.16.2\VCTargetsPath.vcxproj".
Visual Studio project compatibility and VisualStudioVersion
Okay, after much chagrin I found out what was happening.
The ICC 19.0 installer misrecognized the version of Visual Studio and installed MSVS 2015 extensions instead of 2017, which led CMake to believe it should use MSVS 2015 build tools which were simply not there.
Problem solved.
All it took to solve this was to choose «Modify» from the ICC installer menu and switch to the right extension set.

How come cl.exe (Visual Studio compiler) fails to compile a project with CMake (error-report)?

Since I'm new to CMake, I've been attempting to set up a basic CMake application using CMake GUI while following this tutorial. Everything worked fine up until the point when I clicked "Configure". I changed Visual Studio 14 2015 to Visual Studio 16 2019 (because I have a more recent version of Visual Studio) and "Hello World" to "Basic", and after clicking "Configure", I received an error telling me the Visual Studio compiler, cl.exe, could not successfully compile a test program. More details below.
I have already created a CMake project using Visual Studio's built in work-space and it has successfully compiled my project; however, this is undesirable to me as Visual Studio adds a bunch of files to my project that make it look more complicated for a beginner and dirty up my project. This tells me that my Visual Studio installation is not defective, and that something is wrong with CMake.
For those that want to know, my CMakeLists.txt looks like this:
cmake_minimum_required(VERSION "3.10")
project("Basic")
add_executable("${PROJECT_NAME}" "main.cpp")
install(TARGETS "${PROJECT_NAME}" DESTINATION bin)
install(FILES "main.cpp" DESTINATION src)
I expect CMake to configure my project correctly like it does for the guy in the tutorial video, but instead I get an error while configuring that says this (Username replaced by "potato" for personal reasons):
Selecting Windows SDK version 10.0.18362.0 to target Windows 6.1.7601.
The C compiler identification is MSVC 19.23.28106.4
The CXX compiler identification is MSVC 19.23.28106.4
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/potato/Desktop/Basic/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe cmTC_09d22.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.3.1+1def00d3d for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5589,7): error MSB4023: Cannot evaluate the item metadata "%(FullPath)". The item metadata "%(FullPath)" cannot be applied to the path "#(_DebugSymbolsIntermediatePath->'C:\Users\potato\Desktop\Basic\build\CMakeFiles\CMakeTmp\Debug\%(Filename)%(Extension)')". Illegal characters in path. [C:\Users\potato\Desktop\Basic\build\CMakeFiles\CMakeTmp\cmTC_09d22.vcxproj]
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
Configuring incomplete, errors occurred!
See also "C:/Users/potato/Desktop/Basic/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/potato/Desktop/Basic/build/CMakeFiles/CMakeError.log".
CMakeError.log states this:
Determining if the C compiler works failed with the following output:
Change Dir: C:/Users/potato/Desktop/Basic/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe cmTC_09d22.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.3.1+1def00d3d for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5589,7): error MSB4023: Cannot evaluate the item metadata "%(FullPath)". The item metadata "%(FullPath)" cannot be applied to the path "#(_DebugSymbolsIntermediatePath->'C:\Users\potato\Desktop\Basic\build\CMakeFiles\CMakeTmp\Debug\%(Filename)%(Extension)')". Illegal characters in path. [C:\Users\potato\Desktop\Basic\build\CMakeFiles\CMakeTmp\cmTC_09d22.vcxproj]
Perhaps I should also note that the real username, replaced by "potato", contains an apostrophe. This may be only minimal, but it could be important as I read the error "Illegal characters in path."
It turns out that the problem in my case is that the username for my computer contains an apostrophe. Definitely a strange bug.

Visual studio 2017 - building via command line & MSBuild - missing stdafx.h

I have a sln file I usualy compile in visual studio
now I try to compile my project on the command line
I dont use any precompiled headers, so on the command line it feels something is missing because as I do
MSBuild.exe myproject.sln
I get the error
unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"'
like if the config of the project was not read or something
trying to force one config/platform , I get this
c:\myproject>"P:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild".exe game2D_sdl.sln /p:Configuration=Debug /p:Platform=Win32
Microsoft (R) Build Engine version 15.6.82.30579 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 1/03/2019 18:08:47.
Project "c:\myproject\game2D_sdl.sln" on node 1 (default targets).
c:\myproject\game2D_sdl.sln.metaproj : error MSB4126: The specified solution configuration "Debug|Win32" is invalid. Please specify a valid solution configuration using the Configuration an
d Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. [c:\myproject\g
ame2D_sdl.sln]
Done Building Project "c:\myproject\game2D_sdl.sln" (default targets) -- FAILED.
I have disabled PCH in all platforms, just building without forcing the platform, I get includes errors
c:\myproject>"P:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild".exe game2D_sdl.sln
Microsoft (R) Build Engine version 15.6.82.30579 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 1/03/2019 18:13:52.
Project "c:\myproject\game2D_sdl.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|x64".
Project "c:\myproject\game2D_sdl.sln" (1) is building "c:\myproject\game2D_sdl\game2D_sdl.vcxproj" (2) on node 1 (default targets).
InitializeBuildStatus:
Touching "x64\Debug\game2D_sdl.tlog\unsuccessfulbuild".
ClCompile:
P:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\bin\HostX86\x64\CL.exe /c /ZI /nologo /W3 /WX- /diagnostics:classic /sdl /Od /D _DEBUG /D _CONSOLE /D _UNICOD
E /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Debug\\" /Fd"x64\Debug\vc141.pdb" /Gd /TP /FC /errorReport:queue animations.cpp audio.cpp
box.cpp .... animations.cpp .....
c:\myproject\game2d_sdl\game2d_sdl.h(13): fatal error C1083: Cannot open include file: 'nlohmann/json.hpp': No such file or directory [c:\myproject\game2D_sdl\game2D_sdl.vcxproj]
audio.cpp
how do I manage to compile the project properly ?
thanks
Turn off pre compiled headers:
Project Properties -> C++ -> Precompiled Headers
set Precompiled Header to "Not Using Precompiled Header".
You may want to read this answer: What is "stdafx.h" used for in Visual Studio?

Visual studio 2017 and the cl.exe error

I am trying to run the following command in Windows:
pip install flask-sqlalchemy mysql-python
But I get the following error:
cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG / MD -Dversion_info=(1,2,5,'final',1)
-D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" "-Ic:\users\mrnoname\anaconda3\include" "-Ic:
\users\mrnoname\anaconda3\include" /Tc_mysql.c /Fobuild\temp.win-amd64-3.5\Release/
_mysql.obj /Z1
error: command 'cl.exe' failed: No such file or directory
I looked up cl.exe error and found a thread on SO.
Visual studio doesn't have cl.exe
Visual Studio 2015 doesn't install C++ by default. You have to rerun
the setup, select Modify and then check Programming Language -> C++
But for Visual Studio 2017, I don't see such an option. There is no "Programming Language" option to select C++.
I tried installing most of the C++ options (skipping only ones like designed specifically for gaming or other things irrelevant to me) but this didn't solve it.
Does anyone have suggestions for how to correct this for Visual Studio Community 2017?
Did you miss this option in the Visual Studio 2017 Setup?

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:
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?
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:
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.
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):
If you have projects using MFC/ATL libraries you need to add it under SDKs, libraries, and frameworks subcategory:
References
CMake Error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
The CXX compiler identification is unknown
VS 2010 and CMake: 'rc' is not recognized as an internal or external command
I'm using Windows 7.... And after #Florian told me in the comments to look into CMakeFiles/CMakeError.log I managed to fix the problem!
Here is the first log:
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/10/2017 11:05:24 AM.
Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\v141\Toolset.targets(36,5): 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". [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Desktop_PlatformPrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\v141\Toolset.targets(36,5): 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". [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.28
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/10/2017 11:05:24 AM.
Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\v141\Toolset.targets(36,5): 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". [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Desktop_PlatformPrepareForBuild target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Platforms\x64\PlatformToolsets\v141\Toolset.targets(36,5): 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". [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.13
It seemed I needed Windows SDK version 8.1 so I installed it as a component (had only version 10 installed). But then there was another error:
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/10/2017 11:17:21 AM.
Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "Debug\".
Creating directory "Debug\CompilerIdC.tlog\".
InitializeBuildStatus:
Creating "Debug\CompilerIdC.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\CL.exe /c /nologo /W0 /WX- /diagnostics:classic /Od /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc141.pdb" /Gd /TC /errorReport:queue CMakeCCompilerId.c
CMakeCCompilerId.c
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\link.exe /ERRORREPORT:QUEUE /OUT:".\CompilerIdC.exe" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:".\CompilerIdC.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\CompilerIdC.lib" /MACHINE:X64 Debug\CMakeCCompilerId.obj
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdC\CompilerIdC.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.04
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 3/10/2017 11:17:22 AM.
Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "Debug\".
Creating directory "Debug\CompilerIdCXX.tlog\".
InitializeBuildStatus:
Creating "Debug\CompilerIdCXX.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\CL.exe /c /nologo /W0 /WX- /diagnostics:classic /Od /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc141.pdb" /Gd /TP /errorReport:queue CMakeCXXCompilerId.cpp
CMakeCXXCompilerId.cpp
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x64\link.exe /ERRORREPORT:QUEUE /OUT:".\CompilerIdCXX.exe" /INCREMENTAL:NO /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:".\CompilerIdCXX.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:".\CompilerIdCXX.lib" /MACHINE:X64 Debug\CMakeCXXCompilerId.obj
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
Done Building Project "D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default targets) -- FAILED.
Build FAILED.
"D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj" (default target) (1) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' [D:\doctest\build\CMakeFiles\3.8.0-rc2\CompilerIdCXX\CompilerIdCXX.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.60
So LINK : fatal error LNK1104: cannot open file 'ucrtd.lib' sounds a lot like I needed to install more components - and so I did:
Visual C++ runtime for UWP
Windows Universal CRT SDK
And after that the problem is gone!
If you have the Windows 10 Creator's Update SDK installed, it doesn't install the desktop binaries by default, in order to keep the installation size down. CMake will always try to use the latest SDK when it compiles, which will fail as it will be missing binaries such as "gdi32.lib" (that's the first error that occurs for me).
Microsoft list this as a "Known Issue", see Visual C++ Desktop Known Issues.
The Windows 10 Creators Update SDK has been refactored to reduce
installation footprint by default. When you Install this SDK via the
UWP workload, it will not install the headers/libs required for Win32
C++ Desktop Projects.
In order to fix the problem, you need to modify the Visual Studio installation to include the Windows 10 SDK (10.0.15063.0) for Desktop component.
Can tell my experience. After reading CMakeFiles/CMakeError.log found an error
LINK : fatal error LNK1104: cannot open file 'MSVCRTD.lib'
and what's more important - warning
Common7\IDE\VC\VCTargets\Microsoft.CppBuild.targets(402,5):
warning MSB8038: Spectre mitigation is enabled but Spectre mitigated libraries
are not found.
Verify that the Visual Studio Workload includes the Spectre mitigated libraries.
Option 1: I have no intention to use "Spectre-mitigated" libraries and want just to restore previous build behavior.
That means that we need to turn off generating Visual Studio project with correspondent compilation flags on by default since CMake does that to check whether compiler exists and operational.
Luckily found a thread on support forum: https://developercommunity.visualstudio.com/content/problem/348985/installing-wdk-1809-enabled-spectre-mitigation-fla.html
Solution is not very elegant, but works. Put/copy file with name 'Directory.Build.props' to /build folder with content:
<Project>
<PropertyGroup Label="Configuration">
<SpectreMitigation>false</SpectreMitigation>
</PropertyGroup>
</Project>
That overrides default VS behavior and disables /QSpectre compiler switch.
Now CMake's compiler test run passes and no other issues found.
Option 2: ensure that Spectre mitigation libraries installed
See:
https://stackoverflow.com/a/55606007/428685
https://devblogs.microsoft.com/cppblog/spectre-mitigations-in-msvc/
I encountered a similar problem.
It was solved by first un-checking "Desktop Development with C++", and then re-checking "Desktop Development with C++".
Windows 10.0.17134 Build 17134; Visual Studio 2017 Community (15.9.7)
All required components are installed
In my case (Wireshark building), an error was in the wrong toolset. CMake determines v141 while the actual version is v140.
cmake -G "Visual Studio 15 2017" -T v140,host=x64 ..
For me ,I installed vs2015 before,and the c compiler 2015 work before,when i install vs2017, get the same error can't find compiler.
And when i run cmake .. in the vs2017 developer command,it works.
And i can specify generetor to vs2015 or vs2017,it all works.
From my experience the "base" of this CMake workflow problem is the (in this case) really misleading error message "No CMAKE_C[XX]_COMPILER could be found."
CMakeError.log is the key: I saw "...Cl.exe /c..." there, so the compiler was found (and executed)
My problem was a missing ucrt.lib (although the Win10 SDK was there; copied, not "installed", my fault).