msbuild fail on win 2008 R2 on CLI/C++ project - c++

I've just installed VS2012 on my win2008 R2 64 bitserver. Then created simple hello world CLI/C++ projects. When i try to compile this I got the following error:
stdafx.cpp : fatal error C1197: cannot reference 'c:\windows\microsoft.net\framework
\v2.0.50727\mscorlib.dll' as the program has already referenced '
c:\program files (x86)\reference assemblies\microsoft\framework\.netframework
\v4.5\mscorlib.dll' [C:\Users\simbuildop\Documents\Visual Studio 2012\Pr
ojects\ConsoleApplication10\ConsoleApplication10\ConsoleApplication10.vcxproj]
the call to the C++ compiler created by msbuild is:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\CL.exe /c /AI"C:\Program
Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramew
ork\v4.5\\" /AI"C:\Program Files (x86)\Windows Kits\8.0\References
\CommonConfiguration \Neutral" /AI"C:\Program Files (x86)\Reference Assemblies\Mic
rosoft\Framework\.NETFramework\v4.5\Facades\\" /Zi /clr /nologo /W3 /WX- /Od /Oy- /D
WIN32 /D _DEBUG /D _UNICODE /D UNICODE /EHa /MDd /GS /fp:preci
se /Zc:wchar_t /Zc:forScope /Yc"stdafx.h" /Fp"Debug\ConsoleApplication10.pch"
/Fo"Debug\\" /Fd"Debug\vc110.pdb" /TP /FUC:\Windows\Microsoft.NET\Fra
mework\v2.0.50727\mscorlib.dll /FU"C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /FUC:\Window
s\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /FUC:\Windows\Microsoft.NET
\Framework\v2.0.50727\System.Xml.dll /analyze- /errorReport:queue /
clr:nostdlib stdafx.cpp
stdafx.cpp
It is really strange that msbuild is trying to pull .net 2.0 as well as .net 4.5 into the build.
Whats is wrong ?
Regards Michael

I am having this same problem trying to upgrade a VS 2005 project all the way to 2015. I started by upgrading to 2008, and then to 2010 to be able to tap into side-by-side IDE's and round-tripping. My problem was a little different though as I am trying to target .Net 2.0 and not .Net 4.0.
I had to manually update the .vcxproj to use the target framework I wanted using the Project ToolsVersionnoted below.
<Project ToolsVersion="2.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
I also had previously switched the settings to using /CLR which I then switched back to No Common Language Runtime Support. I did a Rebuild after tweaking this and the project built with 0 errors.

Related

Compiling a file the same way Visual Studio does: include path not set

I followed this answer to get the complete command line Visual Studio uses when I press Ctrl+F7 to compile a single file.
That command line is (formatted for readability)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\
VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\CL.exe
/c /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /Oy- /D WIN32 /D _DEBUG
/D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MDd /GS /fp:precise
/permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++20
/Fo"Debug\\" /Fd"Debug\vc142.pdb" /external:W3 /Gd /TP /analyze- /FC
/errorReport:prompt StringFormatting.cpp
I open a Powershell prompt in the directory where StringFormatting.cpp is located.
I copy/paste the exact command line.
I add quotes around the executable name, so that there are no issues with spaces in the path.
The error message I get is
[...] StringFormatting.h(2,10): fatal error C1034: string: no include path set
The first 2 line of the header file are
#pragma once
#include <string>
Obviously it can't resolve the #include <string> which is part of my code. How does Visual Studio tell the compiler the library path?
Thanks to #Adrian Mole I was able to compile using the "Developer command prompt VS 2019". Having a look at the environment variables, I found a lot of include paths:
INCLUDE=
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\ATLMFC\include;
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include;
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt;
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared;
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um;
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt;
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt
Rerunning the compiler with this environment variable solved the problem.
From top to bottom, these paths are for (thanks to #Chuck Walbourn):
Microsoft ATL (Active Template Library; ActiveX, COM)
C++ Standard library
C++/CLI (Common Language Infrastructure; .NET Interface, formerly "managed C++")
Standard C Library
Win32 Desktop development (Windows SDK)
Win32 Desktop development (Windows SDK)
Windows Runtime API
Windows Runtime API (C++/WinRT projections)

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?

CMake with Microsoft Visual C++ Build Tools

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.

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).

How do I change the compiler and CXX_FLAGS for CMAKE of a C++ project?

I'm currently working on an unmanaged Windows C++ application.
I'm new to the world of CMAKE and C++.
I'm also new to the world of this current unmanaged C++ application.
I'm trying to integrate DevPartner into my build to instrument the build for memory errors and runtime errors.
In order to build for instrumentation, I need to change to using the DevPartner compiler (nmcl.exe).
Additionally, I need to add compiler settings to the existing CXX_FLAGS for instrumentation.
How do I go about doing this?
For VS releases 2008 and earlier.... (Except VS6 it uses msdev)
Well digging more into cmake I will say this someone with more knowledge will be able to take this and run with it.
I did find that the CL and LINK commands really do nothing since this just kicks off Devenv for VS2003 to 2008 and MSBuild for VS2010. Changing CL to NMCL will not matter since MSBuild uses the targets files which is why my other answer needs the user files modified. And why we need to use another tool here.
Devenv called with /Build internally uses the project files to know what source files need to be built. It will then call createprocess internally to spawn CL and LINK as needed. This is why changing CL to NMCL in the cmake files is useless.
Luckily we have another tool that can be used here....
We need to change
//make program
CMAKE_MAKE_PROGRAM:FILEPATH=C:/Program Files (x86)/Common Files/Micro Focus/NMShared/CTI/11.1/NMdevenv.EXE
and
CMAKE_BUILD_TOOL:INTERNAL=e:/PROGRA~1/MICROS~2.0/Common7/IDE/devenv.com
to C:/Program Files (x86)/Common Files/Micro Focus/NMShared/CTI/11.1/NMdevenv.EXE
Now this is where someone with a little more knowledge is needed. We also need to pass the type of instrumentation to nmdevenv as the 1st parameters.
I believe it can be done something like this
set(CMAKE_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM} " /nmon")
One other issue here is that we need devenv to be in the path as well so the Path env variable will need to be set correctly as well. This can be done by running the correct vscvars bat file.
Hope this helps and if you are using vs2008 and previous please add the steps needed to what I started here. I am sure it will help other users in the long run. If I get some more time to investigate this I will find the way to do it.
Edit
Well I did manage to get this working with VS2008. I did have to make a change to our nmdevenv wrapper as cmake was trashing our SearchPath functionality.
Here is what I did.
Replaced the make program as above
Ran VCVars32
Ran cmake --build mytestproj
Ran the program under BounsChecker
Now I switched to pass in /nmtxon for performance profiling
This had me stumped for a bit as it kept compiling for Error Detection
And that is when I found this in the converted project files
<Tool
Name="VCCLCompilerTool"
AdditionalOptions=" /NMbcon /Zm1000"
Changed that to
and all is well. I had my performance compiled option.
So I went back and modified this line in the CMakeCache.txt file opened the GUI, configue, generate
//Flags used by the compiler during all build types.
CMAKE_CXX_FLAGS:STRING= /NMbcon /DWIN32 /D_WINDOWS /W3 /Zm1000 /EHsc /GR
Then the project was switched back to use /NMbcon. So that is the correct spot to put the switch if you want to compile all with us. Otherwise use the appropriate Debug or release line.
portion of Cmake output
Notice Instrumenting in the output
Microsoft (R) Visual Studio Version 9.0.30729.1.
Copyright (C) Microsoft Corp. All rights reserved.
1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>Compiling...
New Command line nmcl.exe /NMtxon #e:\cust\Test3\Test\Test.dir\Debug\RSP0000011
2568792.rsp /nologo /errorReport:queue
1>Test3.cpp
1>Instrumenting ..\Test3\Test3.cpp
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.7600.16385
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Linking...
In summary
Use Cmake to generate the CMakeCache.txt and directories
Modify CmakeCahe
Use NMDevenv as the MAKE program
Add /NMon switch to the flags
run CmakeGui and generate again
Run VCVars32
Run cmake --build file
Run the program under devpartner
Which version of Visual Studio are you using? That makes a fair amount of difference, as how the instrumentation is managed has changed over the years . . . not so much by version of DevPartner as by version of Visual Studio.
Not 100% sure for a cmake file but this is from an old VS 6 makefile modified for Devpartner. Perhaps you can post a relevant section of the makefile for me to look at.
/nmbcon is a compile flag that says use BC instrumentation /nmtxon would be used for coverage analysis
CPP=cl.exe
CPP_PROJ=/nologo /MD /W3 /Gm /GX /Zi /Od /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_AFXEXT" /Fp"$(INTDIR)\main.pch" /Yu"stdafx.h" /Fo"$(INTDIR)\" /Fd"..\bin\Debug\MAIN.pdb" /FD /GZ /c
Would become
CPP=nmcl.exe
CPP_PROJ= /nmbcon /nologo /MD /W3 /Gm /GX /Zi /Od /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_AFXEXT" /Fp"$(INTDIR)\main.pch" /Yu"stdafx.h" /Fo"$(INTDIR)\" /Fd"..\bin\Debug\MAIN.pdb" /FD /GZ /c
Oh and the other poster is correct things have greatly changed by version of Visual Studio. VS2010 changed the build process to use MSBuild this caused us to completely modify the way we intercept and instterument for VS2010 and 2012.
*EDIT
Well I did download and go through the pain of Cmake internship this morning. For VS2010 this seems to be a pretty simple modification just like would be needed for one of our users using MSBuild from the command line.
In the out dir "Where to build the binaries" after the first build there will be .vcxproj.user files. This is where you need to add the flags for instrumentation
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<DevPartner_IsInstrumented>1</DevPartner_IsInstrumented>
<DevPartner_Instrumented_Type> /NMbcOn</DevPartner_Instrumented_Type>
</PropertyGroup>
</Project>
This can be a repeating section for each
that you wish to build.
The next key DevPartner_IsInstrumented tells us to instrument (1) or not (0).
The last key DevPartner_Instrumented_Type> is what type to instrumetnt /nmbcon (Boundschecker) /nmtxon (Performance or Coverage) or both keys passed.
So it could look like
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<DevPartner_IsInstrumented>1</DevPartner_IsInstrumented>
<DevPartner_Instrumented_Type> /NMbcOn</DevPartner_Instrumented_Type>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<DevPartner_IsInstrumented>0</DevPartner_IsInstrumented>
<DevPartner_Instrumented_Type> /NMbcOn</DevPartner_Instrumented_Type>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DevPartner_IsInstrumented>0</DevPartner_IsInstrumented>
<DevPartner_Instrumented_Type> /NMbcOn</DevPartner_Instrumented_Type>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DevPartner_IsInstrumented>1</DevPartner_IsInstrumented>
<DevPartner_Instrumented_Type> /NtxcOn</DevPartner_Instrumented_Type>
</PropertyGroup>
</Project>
which would be Boundschecker for Debug win32, nothing for Release win32, nothing for debug x64 and Performance / Coverage for release x64
If IsInstrumented 0 whatever is in the type will not matter as it will not be passed.
FYI if you open the solution in VS2010 and turn instrumentation on this will be added to the vcxproj.user files for you. And the instrumentation settings are by project / config as well.
If not using VS2010 my note below might be correct for those versions.
For full disclosure I am the lead developer on the instrumentation engine for DevPartner.