0

I'm trying to add ARM platform support to an existing Visual C++ project. I want to ensure the project can build Windows Phone and Windows Store apps in addition to X86 and X64 programs.

Microsoft does not appear to provide official documentation on the subject matter (or I can't seem to find it). In the absence of official documentation, I'm following the discussion provided on Microsoft Blogs at A guide to .vcxproj and .props file structure. I think the blog is quite good, and I don't think it has any defects, errors or omissions.

lib.vcxproj is an MCVE and its shown below. When I build an X86 or X64 target using a Visual Studio C++ project file from a VS{2010|2012|2013} X86 or X64 Developer Command Prompt, then things work as expected:

c:\Users\Test>msbuild /t:Build /p:Configuration=Debug;Platform=x64 lib.vcxproj
Microsoft (R) Build Engine version 4.6.1055.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10/7/2016 3:03:15 PM.
Project "c:\Users\Test\lib.vcxproj" on node 1 (Build target(s)).
...

Done Building Project "c:\Users\Test\lib.vcxproj" (Build target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

When I uncomment the ARM specific gear:

<ProjectConfiguration Include="Debug|ARM">
  <Configuration>Debug</Configuration>
  <Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
  <Configuration>Release</Configuration>
  <Platform>ARM</Platform>
</ProjectConfiguration>

Then switch to a ARM Developer Command Prompt and attempt to build it, the result is a failure:

c:\Users\Test>msbuild /t:Build /p:Configuration=Debug;Platform=ARM lib.vcxproj
Microsoft (R) Build Engine version 4.6.1055.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10/7/2016 7:43:12 PM.
Project "c:\Users\Test\lib.vcxproj" on node 1 (Build target(s)).
c:\Users\Test\lib.vcxproj : error MSB4057: The target "Build" does not exist in 
the project.
Done Building Project "c:\Users\Test\lib.vcxproj" (Build target(s)) -- FAILED.

Build FAILED.

"c:\Users\Test\lib.vcxproj" (Build target) (1) ->
  c:\Users\Test\lib.vcxproj : error MSB4057: The target "Build" does not exist i
n the project.

    0 Warning(s)
    1 Error(s)

All the ARM tools are installed correctly. I regularly build the project from the command line with Nmake using an ARM Developer Command Prompt.

According to the feedback at Can MSBuild be used to build a C++ project under ARM?, MSBuild does support ARM.

According to Difference between 2003 and current MSBuild schemas, I should continue to use the 2003 version of the schema.

How do I add ARM Platform support to existing Visual C++, MSBuild-based Project?


If you receive the "Compiling desktop applications for the ARM platform is not supported" error message, then add the following:

<ClCompile>
  <PreprocessorDefinitions>WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>

It can be added to the ItemDefinitionGroup for ARM, near the PrecomiledHeader option.


lib.cpp

// One symbol
static const int s_int = 1;

lib.vcxproj

<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>

    <!-- BEGIN Added for ARM -->
    <!--
    <ProjectConfiguration Include="Debug|ARM">
      <Configuration>Debug</Configuration>
      <Platform>ARM</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|ARM">
      <Configuration>Release</Configuration>
      <Platform>ARM</Platform>
    </ProjectConfiguration>
    -->
    <!-- END Added for ARM -->
  </ItemGroup>
  <PropertyGroup Label="Globals">
      <ProjectGuid>{111111-1111-1111-1111-111111111111}</ProjectGuid>
      <RootNamespace>test</RootNamespace>
      <PlatformToolset>v100</PlatformToolset>
      <ConfigurationType>StaticLibrary</ConfigurationType>
    </PropertyGroup>

  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

  <ImportGroup Label="ExtensionSettings" />
  <ImportGroup Label="PropertySheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />

  <!-- X86 Configurations -->
  <ItemDefinitionGroup Condition="'$(Platform)'=='Win32'" Label="X86 Configuration">
    <ClCompile>
      <PrecompiledHeader />
    </ClCompile>
    <Lib>
      <TargetMachine>MachineX86</TargetMachine>
      <ImageHasSafeExceptionHandlers>true</ImageHasSafeExceptionHandlers>
    </Lib>
  </ItemDefinitionGroup>

  <!-- X64 Configurations -->
  <ItemDefinitionGroup Condition="'$(Platform)'=='x64'" Label="X64 Configuration">
    <ClCompile>
      <PrecompiledHeader />
    </ClCompile>
    <Lib>
      <TargetMachine>MachineX64</TargetMachine>
    </Lib>
  </ItemDefinitionGroup>  

  <!-- ARM Configurations -->
  <ItemDefinitionGroup Condition="'$(Platform)'=='ARM'" Label="ARM Configuration">
    <ClCompile>
      <PrecompiledHeader />
    </ClCompile>
    <Lib>
      <TargetMachine>MachineARM</TargetMachine>
    </Lib>
  </ItemDefinitionGroup>

  <ItemGroup>
    <ClCompile Include="lib.cpp" />
  </ItemGroup>

  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

No, this is not a duplicate. See the comment that explains why.

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885
  • 2
    Are you really adding those `ProjectConfiguration` elements _outside_ the `ItemGroup` containing the existing ones? I don't even need to look at the error message or the schema to suspect an obvious problem there... There's also always the option of just firing up VS and adding a new platform via the configuration manager to see how that works out. – Notlikethat Oct 07 '16 at 21:03
  • Good catch @Notlikethat - Yes, its wrong in the MCVE. Its now fixed. Its correct in the MCVE and real project, and it still produces the errors. – jww Oct 07 '16 at 21:22
  • Well, for me, fixing that results in at least a _different_ error; the good old "Compiling desktop applications for the ARM platform is not supported" (admittedly I'm not actually using VS2010, and had to hack `PlatformToolset` to "v110" to get that far under the VS2012 command prompt from whatever Windows Phone SDK was installed by VS2015). At worst, there's always the option of firing up VS itself, adding a new platform to the project through the configuration manager, and seeing the difference that makes. – Notlikethat Oct 07 '16 at 21:54
  • @Notlikethat - *"Compiling desktop applications for the ARM platform is not supported"* - you can add `/DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP` to `CXXFLAGS`. I do it all the time under the ARM Developer Command Prompt when using Nmake. I updated the answer to show you the MSBuild way. However, it does not seem to work as expected under MSBuild. For completeness, here's a list of different `CXXFLAGS` I use for the platforms under Nmake: [cryptest.namke](http://github.com/weidai11/cryptopp/blob/master/cryptest.nmake#L27). Nmake works fine almost all the time; WinRT is the [broken] exception. – jww Oct 08 '16 at 04:42
  • Possible duplicate of [Can MSBuild be used to build a C++ project under ARM?](http://stackoverflow.com/questions/39902108/can-msbuild-be-used-to-build-a-c-project-under-arm) – stijn Oct 08 '16 at 08:13
  • 1) do you have the same when using other toolsets than v100? 2) as asked in the other question: does it work when you create a new empty project via VS? – stijn Oct 08 '16 at 08:15
  • Adding to the compiler flags cannot possibly solve MSB8022 (error message here points me to ARM's toolsets.targets line 36 and compiler flags are not checked there - it's always useful to check why the Error task is issued); instead I set the WindowsSDKDesktopARMSupport property to true and your lib.vcxproj builds without any problems. But even before that I couldn't get the MSB4057 error. – stijn Oct 08 '16 at 08:27
  • 1
    @stijn - Not a duplicate. I try to ask concise questions. The dup you cited asks if its possible. This questions asks how to accomplish it. This question also provides an MCVE attempting to demonstrate it. They are two different questions building on one another. – jww Oct 08 '16 at 08:29
  • @stijn - I don't believe `WindowsSDKDesktopARMSupport` is the correct path. I'm trying to build a phone or store app; I'm not trying to trick the machinery into a WinRT/ARM desktop app. As far as I know, only Microsoft can build WinRT/ARM desktop apps. They don't allow developers to install them or run them. I learned the last part after I spent a couple thousand on a WinRT tablet. I basically was not allowed to use it. I bet Ballmer is still laughing at folks like me who who thought we could actually use it the way we use our other stuff. – jww Oct 08 '16 at 08:38
  • *The dup you cited asks if its possible.* well suppose the answer is *yes* your immediate next question would be *how* anyway so it would be beneficial for future visitors if that is answered in the same question. Anyway I didn't post the WindowsSDKDesktopARMSupport hack as an answer because I don't know if its's the correct way to do it, it's just what I figured out. And I'm not alone: http://stackoverflow.com/questions/11151474/can-arm-desktop-programs-be-built-using-visual-studio-2012 (which also asks both *possible* and *how* btw) – stijn Oct 08 '16 at 09:06
  • 1
    Thanks @stijn. I'm familiar with the question [Can ARM desktop programs be built using visual studio 2012?](http://stackoverflow.com/q/11151474/608639) It misses the mark because its WinRT/ARM, and only Microsoft is allowed to do anything useful with it. `WindowsSDKDesktopARMSupport` and WinRT are ***not*** the solution to any problem because its Microsoft exclusive. I know the details because I bought and tested the WinRT tablet; and I worked feature request for improved [Windows Phone, Windows Store and UWP support](http://github.com/weidai11/cryptopp/issues/143). – jww Oct 08 '16 at 09:18

0 Answers0