Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building C++ project on a PC with Windows SDK 7.1 but without VS2010

I have a C++ project (some sort of a console 32-bit appplication) developed in VS2010, which builds just fine on my PC (Windows 7 32-bit). My PC has Microsoft SDK 7.0A installed, which I think comes bundled with VS2010.
I try to build the project on a build server, which doesn't have any Visual Studio installed - only Microsoft SDK 7.1 is present there.
I try to build the project with the help of msbuild (this will eventually become the task for TeamCity's runner), and on the build server I get following errors (the detailed log is provided):

Project "E:\win\core.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|Win32".
Project "E:\win\core.sln" (1) is building "E:\win\core_unittests.vcxproj" (2) on node 1 (default targets).
Project "E:\win\core_unittests.vcxproj" (2) is building "E:\cpptest\win\cpptest.vcxproj" (3) on node 1 (default targets).
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(847,9): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [E:\cpptest\win\cpptest.vcxproj]
C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(297,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [E:\win\cpptest.vcxproj]
InitializeBuildStatus:
  Touching "E:\cpptest\win\..\..\..\out\Debug\cpptest\cpptest.unsuccessfulbuild".
ClCompile:
  C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MTd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"E:\cpptest\win\..\..\..\out\Debug\cpptest\\" /Fd"E:\cpptest\win\..\..\..\out\Debug\cpptest\vc100.pdb" /Gd /TP /analyze- /errorReport:queue ../missing.cpp
  missing.cpp
e:\cpptest\missing.cpp(36): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory [E:\cpptest\win\cpptest.vcxproj]

I suppose the issue is related to inability of msbuild to find Microsoft SDK, which is installed into "E:\Program Files\Microsoft SDKs\Windows\v7.1".

There are few advices how to handle this issue available on the Web:

  1. Copy part of registry under HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1 to HKCU (see WindowsSdkDir is not set correctly in Visual Studio 2008?). I didn't try this workaround because as it looks too ugly, and the build process will run with SYSTEM-account credentials.
  2. Pass WindowsSDKDir as an extra parameters to MSBuild (as proposed in TeamCity and MSBuild Quirks #1).
  3. Tweaking VCProjectEngine.dll.config.xml as proposed in the answer to Include Search Paths in TeamCity build Configurations (I haven't found such file on the PC with Windows SDK).
  4. Change the platform toolset in the project properties as proposed in the answer to WindowsSdkDir is not set correctly in Visual Studio 2010 (I doubt this will help, because my PC doesn't have Windows SDK 7.1 installed).

Actually when compiling with CL.EXE everything goes fine (because I have INCLUDE and LIB variables defined), so it would be a workaround to force msbuild to use/pass the environment variables...

There are similar issues:

  • "Differences between building on a machine with VS2010 installed and on a machine with the 7.1 SDK installed" but for .NET projects.
  • Erroneous Windows SDK x64 Compilation Warning (building 32-bit project for 64-bit platform).

Anyway has anyone succeeded with building Visual C++ 2010 projects on a PC with Windows SDK installed?

like image 684
AntonK Avatar asked Dec 26 '11 14:12

AntonK


1 Answers

I've finally found some kind of a workable and meaningful workaround for the issue - inside "Can we build *.vcxproj(c++ project) using MSBuild 4.0 without installing the Visual Studio 2010?".
In short: I have to explicitly specify the Platform Toolset when building the solution on a PC without VS2010. The command will look like:

msbuild /p:PlatformToolset=Windows7.1SDK core.sln

You will probably need to go same way if your project has v100 or v90 specified as the Platform Toolset.

And an extra hint for TeamCity's enthusiasts, running the server on a PC with a lone Windows SDK installed.
Instead of modifying all build steps, it is enough to specify the Platform Toolset in the agent's properties. To do that add following line to ?:\TeamCity\buildAgent\conf\buildAgent.properties:

system.PlatformToolset=Windows7.1SDK

Happy building! :)

like image 160
AntonK Avatar answered Oct 26 '22 23:10

AntonK