Experimenting with Intel C++ Compiler 13.0 or 14.0 and Windows* 8 Store Apps

Table of content

  1. Terminology and Abbreviations
  2. Overview
  3. Summary
  4. Prerequisite
  5. Visual C++ component extensions (C++/CX)
  6. WinRT, WRL and COM
  7. Ordinary win32 Libraries
  8. Limitations of the Intel C++ Compiler in Building a Windows 8 Store Application
  9. Known Issues of the Intel C++ Compiler in Building a Windows 8 Store Application
  10. How the Intel C++ Compiler Can Help a Windows 8 Store App
  11. Project Types for Windows 8 Store Apps where the Intel C++ Compiler Can Be Used
  12. Using the Intel C++ Compiler within Visual Studio 2012 IDE
  13. Using Intel C++ Compiler with Visual Studio 2012 Express Edition
  14. Examples
  15. Conclusion

Terminology and Abbreviations

WinRT - Windows* Runtime for Windows 8*
WRL - Windows C++ Runtime Template Library
COM technology - Component Object Model technology
C++/CX - Visual C++ component extensions
VS2012 – Microsoft* Visual Studio 2012*

Overview

With the recent release of Microsoft* Visual Studio 2012 and Windows 8*, many may wonder if the Intel® C++ Compiler can be used for developing the new Windows 8 store apps.

The new Windows 8 Store apps can be created using different programming languages: C++/CX (the new extensions in Visual C++ 2012), Visual Basic, Visual C#, and Java Script. From Martyn Lovel’s talk on “Lap around the Windows Runtime”, using the C++/CX language has the least overhead when calling the WinRT runtime APIs among the 4 languages.

The Intel C++ compiler is known for its advanced compiler optimization and can generate binaries optimized for specific processors to achieve better performance. While the Intel C++ Compiler does not support Visual Studio 2012 for Windows 8 Store apps at the moment, this article will guide you through the issues and limitations to experiment using the Intel C++ compiler with your Windows 8 Store app. 

Summary

Visual Studio 2012 has introduced the C++ component extensions (C++/CX) including C++ language extensions, new predefined macros, new compiler options and linker options for easy development of Windows 8 Store apps. Currently the Intel C++ Compiler does NOT support the C++ component extensions. 

Windows Runtime (WinRT) is the foundation of the new Windows 8 Store apps. For C++ developers who prefer using just C++ language without CX, Windows C++ Runtime Template Library (WRL) is an alternative. WRL DLL is like COM DLL but no need of registration.

WRL components, static and dynamic libraries can be used by the Windows 8 Store apps. These are where the Intel C++ compiler can be used and help with performance.

From the C++ language point of view since the Intel C++ Compiler is still source and binary compatible with the Visual C++ compiler that means mixing and matching objects or DLLs or libs built by those two compilers is okay. Although the Intel C++ Compiler is great with optimization, there is no need to build the whole app with it, but only modules that contain intensive calculations or a performance bottleneck.  Intel C++ Compiler features such as Auto Vectorization, High Level Optimization, C++11 support and Intel Cilk Plus® Array Notation ( with the exception of the cilk_for keyword ) can be used in your Windows 8 Store application.

The Intel C++ Compiler is integrated into Visual Studio 2012 Professional or above through “Project”, “Project Context Menu” and “Tools Option” dialog.

Prerequisite

The following software is required in order to use the Intel C++ compiler:

  • OS: Microsoft Windows 8 (x64 recommended)
  • Visual Studio 2012 professional or above; or Visual Studio 2012 express edition1) for Windows 8
    Note 1): for Visual Studio 2012 express edition, the Intel C++ Compiler will not be available within the Visual Studio IDE. It means that the Intel C++ Compiler can only be used from a command prompt. This is a limitation of all Visual Studio express edition.
  • Intel® C++ Composer XE 2013 for Windows or Intel® C++ Composer XE 2013 SP1 for Windows

Visual C++ component extensions (C++/CX)

Visual Studio 2012 has introduced new Visual C++ component extensions to simplify the development of Windows 8 Store apps. The extensions include:

  • New C++/CX language keywords and types: ref, ^, sealed, task.then(). Refer to Microsoft website Quick Reference (C++/CX) for more detail list.
  • New compiler options: /ZW, /ZW:nostdlib, /FU etc.
  • New predefined macro: WINAPI_FAMILY_APP for Windows Store apps. Use /D "WINAPI_FAMILY=WINAPI_FAMILY_APP" for targeting Windows Store app.
  • New linker options: /APPCONTAINER, /WINMD, /WINMDFILE etc.
    Note: a complete list of new options can be found at Microsoft website Compiler and Linker options for WinRT.

Currently the Intel C++ Compiler does NOT support the new Visual C++ component extensions or the new compiler/linker options.

How can the Intel C++ Compiler be used in optimizing your Windows 8 Store app? Let us explore some more detail of Windows 8 WinRT. 

WinRT, WRL and COM

Ever since year 2011 BUILD conference, there are many postings and blogs about WinRT and COM.

WinRT is the backbone of Windows 8 Store apps; it is basically written with the COM technology. For those who know COM, it is easier to understand how apps with multiple programming languages can interact with WinRT.

The Windows Runtime C++ Template Library (WRL) is a COM-based template library that provides a low-level mechanism to use WinRT components. More information about the WRL and examples can be found at WRL Fundamentals.

Both Visual C++ component extensions (C++/CX) and the WRL (like RuntimeClass<>, ComPtr<>) take care of the tedious/repetitive coding (like AddRef(), Release() etc.) for you to simplify the Windows 8 Store app programming. It is your choice on which one to use and it is perfectly fine to use both in your app. But the Intel C++ Compiler only works with WRL at the moment.

The sample “Creating a Windows Runtime DLL component with C++ sample” in the C++ Samples posted on MSDN “Windows 8 app samples – C#, VT.NET, C++, JavaScript” demonstrates how a WRL DLL component is implemented and consumed by UI layer in other languages (C++, C# & JavaScript). Note that the core WRL DLL “WRLInProcessWinRTComponent_server” can be compiled with Intel C++ Compiler successfully.

The table below shows how the code looks like with WRL compared to C++/CX. 

C++/CXWRL (project name “MyWRL_dll”)
myApp.h: create a WinRT class in CX
namespace MyWRL_dll
{
    public ref class MyTest sealed
    {
    public:
        MyTest ();
        double TestMe(double a);
    };
}
myApp.cpp
#include "WinRTComponent.h"

using namespace winrtCompDll;
using namespace Platform;

MyTest:: MyTest ()
{
}
double MyTest::TestMe(double a)
{
    return a+10;
}
MyWRL_dll.idl: create a WinRT class in WRL
import "Windows.Foundation.idl";

namespace MyWRL_dll
{
[uuid(xxx) , version(1.0), exclusiveto(MyTest)]
interface IMyTest : IInspectable
{
    HRESULT TestMe([in]double a, 
                [out, retval] double* ret);
};
[version(1.0), activatable(1.0)]
runtimeclass MyTest
{
    [default] interface IMyTest;
}
}
MyTest.h
#include “myWRL_h.h”
#include <wrl.h>

using namespace Microsoft::WRL;
using namespace Windows::Foundation;
namespace ABI {
namespace MyWRL_dll {
class MyTest:	

public RuntimeClass<IMyTest> {
InspectableClass(L"MyWRL_dll.MyTest", 
                    TrustLevel::BaseTrust);
public:
    MyTest ();
IFACEMETHOD(TestMe)(_In_ double a, 
                _COM_Outptr_double* ret);
};

ActivatableClass (MyTest);
}
}

myTest.cpp
#include “myTest.h”
using namespace MyWRL_dll;

MyTest:: MyTest () {}
HRESULT STDMETHODCALLTYPE MyTest::TestMe(
                /*[in]*/double a, 
                /*[out,retval]*/double* ret) 
{
    *ret = a+10;
    return S_OK;
}
test.cpp: consuming the WinRT class using CX
#include “myApp.h” 

MyTest ^ myTest = ref new MyTest();

double d = myTest.TestMe(3.14);

Test_wrl.cpp: consuming the WinRT class using WRL.
#include <wrl\client.h>
#include <wrl\wrappers\corewrappers.h>
#include “myApp_comp.h”
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::MatrixMultiplyWRLDLLIC;
using Windows::Foundation; 
// Initialize the Windows Runtime.
RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
if (SUCCEEDED(initialize))
{
  // create an instance of the runtime class MyMatrix
  HStringReference runtimeClassMyMatrix
        (L"MatrixMultiplyWRLDLLIC.MyMatrix");
  ComPtr< IMyMatrix > pIMyMatrix; 
  HRESULT hr = ActivateInstance<ComPtr<IMyMatrix> >
        ( runtimeClassMyMatrix.Get(), &pIMyMatrix );
  // call the interface method
  UINT32 d; 
  if (SUCCEEDED(hr))
    hr = pIMyMatrix->TestMe(3, &d);
}

You can find more information from MSDN How to: Load and Use a Windows Runtime Component (WRL) page.

In the sample “MatrixSample” below, method “UINT32 CPPMetroApp:: MainPage::ConsumingWRLInCplusplus()” in MainPage.xaml.cpp of project “CppMetroApp” demonstrates  how to access the WRL interface IMyMatrix::TestMe()in MatrixMultipleWRLDLLIC.dll using C++ only instead of CX. You can debug and step through the code by simply uncomment line 257 of MainPage.xaml.cpp in project “CppMetroApp”.

Ordinary win32 Libraries

Most applications consist of many components or modules that are either static libraries or dynamic libraries. The good news is that C++ win32 libraries can be used in the Windows 8 Store apps as well. See this MSDN thread, one win32 dll for both, and use a chain of win32 dll for more information.

So for any existing win32 libraries, you need to rebuild them with Visual Studio 2012 and set the property “Windows Store App Support” to “Yes”. For those win32 libraries they can be built with Intel C++ compiler within the Visual Studio 2012 IDE, or from command line. 

Limitations of the Intel C++ Compiler in Building a Windows 8 Store Application

The Intel C++ compiler can be used for building a DLL or library module of your Windows Store app written in the C/C++ language. It supports many C++11 (also named C++0x) features. The full list of supported C++11 features is listed in article C++11 Features Supported by Intel C++ Compiler including Lambdas V1.0 support that is widely used in many samples of Windows 8 Store apps.

Although it is possible to use Intel C++ compiler to build a Windows 8 Store application, please note it is not supported. You can experiment it with your app. The areas of known issues & limitations are:

  1. The Intel C++ compiler does not support the new Visual C++ component extensions as mentioned above. The work-around is to use the Windows C++ Template Library (WRL).
  2. The runtime libraries of the Intel C++ compiler are not compliant with technical requirements of Windows 8 Store app, meaning that you cannot include those libraries in your app package, otherwise your app will not pass the Application Certification Kit test. The work-around is to use the “/Zl” option to link with Microsoft Visual Studio 2012 runtime libraries.
    Note: Depending on your application, the Intel C++ compiler runtime libraries may or may not be linked in your application. If linking the static libraries, the final application may not use any non-compliant APIs. We only encourage you to try out the Intel C++ compiler with your application.
    Although Intel C++ compiler libraries that are not compliant with Windows 8 Store app requirements, for static linked libraries, because of the application type, not all APIs will be linked. So the chances are the final app may be ok.

Known Issues of the Intel C++ Compiler in Building a Windows 8 Store Application

  1. Using /Qip to avoid link time issue if using WRL component from Visual Studio 2012 online template
    If you created the WRL component from Visual Studio 2012 online template, when building such project with Intel C++ compiler 13.x or 14.0, you will see the following unresolved symbols at link time:

    MatrixMultiplyWRLDLLIC.exp : error LNK2001: unresolved external symbol _DllCanUnloadNow@0
    MatrixMultiplyWRLDLLIC.exp : error LNK2001: unresolved external symbol _DllGetActivationFactory@8
    MatrixMultiplyWRLDLLIC.exp : error LNK2001: unresolved external symbol _DllGetClassObject@12

    The root cause is the following code in “module.cpp”:

    #pragma comment /EXPORT:DllCanUnloadNow=_DllCanUnloadNow@0,PRIVATE"

    The work-around is to change the /Qipo to /Qip in the project property:


    Figure 1 - Set /Qip project property
  2. Using “/Zl” (omit default library name in .OBJ) to avoid linking with dynamic libraries from the Intel C++ Compiler. This is because the dynamic libraries in the Intel C++ Compiler are not compliant with Windows 8 Store app requirements yet.

    To set “/Zl” (omit default library name in .OBJ) option in VS2012 IDE:


    Figure 2 – Set /Zl option to omit default library name in .obj file

How the Intel C++ Compiler Can Help a Windows 8 Store App

For most big applications or Windows 8 Store apps, they are structured with many components: UI module, core components, data storage components, etc. There is no need to build the whole app with the Intel C++ compiler, but only the computation intensive components or the performance bottleneck modules. Switching compilers is a big task; it’s costly in time and resources.

Many optimizations offered by the Intel C++ Compiler can be used for your application:

  • Vectorization (/Q[a]xXXX e.g. /QxAVX, /QaxSSE3, /QxCORE-AVX-I etc)
  • High Level Optimization (/O3)
  • C++0x (C++11) support (/Qstd=c++11)
  • Array Notation feature

Because the Intel Cilk plus libraries and OpenMP libraries are not compliant with Windows 8 Store app requirement, you should not use them in your app.

For information on building only part of your application with the Intel C++ Compiler, see Get An Easy Performance Boost.  There is a great recording on vectorization - Future-Proof Your Application's Performance with Vectorization Technical Presentation. Also please refer to the Intel C++ Compiler Documentation for details on all features.

Project Types for Windows 8 Store Apps where the Intel C++ Compiler Can Be Used

The screen capture below shows that the Intel C++ compiler can be used in five types of Windows 8 Store project types:


Intel C++ Compiler could be used for C++ code only (not CX code)
Intel C++ Compiler could be used
Figure 3 – Project types for Windows Store app where the Intel C++ compiler can be used.

For the WinRT Component DLL project it is only possible to use the Intel C++ compiler for source code that does not use the C++/CX features.

Note: The project template for a WRL Class Library is not installed by default. It is available from Visual Studio 2012 online template. Once you selected the online WRL Class Library template like below, it will be installed and available from project template list.


Figure 4 - Online project template “WRL Class Library”

Following table describes the detail information on building each of the 4 project types using Intel C++ Compiler:

Project TypeBuild issue and Workaround
Static Library (Windows Store apps) Using /Zl to avoid linking Intel C++ runtime libraries
DLL (Windows Store apps) Using /Zl too
Unit Test Library No issues
WRL Class Library Using /Zl and do not use /Qipo
Windows Runtime Component Use the Intel C++ compiler to build the pure C/C++ source code.
Note: set “Use Precompiled Header File” to “No” for the files built with Intel C++.

Using the Intel C++ Compiler within Visual Studio 2012 IDE

The Intel C++ Composer XE 2013 (or SP1) is integrated into Visual Studio 2012 professional or above. The integration provides easy use of the Intel C++ compiler through “Project”, “Project Context Menu” and “Tools Option” dialog. The support for the Windows 8 Store app is not complete. The following provides the steps on how to use the Intel C++ compiler to build the four types of Windows 8 Store app projects:

  1. Right click on project name “MatrixMultiplyWRLDLLIC” and select “Intel Composer XE 2013 > Use Intel C++”:
    This sets the “Platform Toolset” on the Project Property dialog to “Intel C++ Compiler XE 13.0” if you're using Intel C++ Composer XE 2013, and set to “Intel C++ Compiler XE 14.0” if you are using Intel C++ Composer XE 2013 SP1.

    Figure 5 – Set the project to use Intel C++
  2. Update project settings accordingly and rebuild the project with the Intel C++ compiler:
    Note: The Intel C++ Compiler offers a set of processor targeting switches. For the detailed information, please refer to the article “Intel® Compiler Options for Intel® SSE and Intel® AVX generation and processor-specific optimizations” for detailed descriptions of the switches and the targeted processors. This screen capture below shows how to set the switch for the project:

    Figure 6 – Set processor specific optimization options offered by Intel C++ compiler

Using Intel C++ Compiler with Visual Studio 2012 Express Edition

Microsoft Visual Studio Express Edition does not allow the VSIP integration for 3rd party tools so the Intel C++ compiler will not be available within the IDE. You can use the Intel C++ compiler from the command prompt.

After the Intel C++ Composer XE 2013 (or SP1) for Windows is installed, two command prompts under the [Start] menu are created that set up the correct compiler/linker environment for building your C++ app.

The Windows 8 does not have a [Start] menu by default, so it is not easy to open a command prompt like on Windows 7. Here is how you can open the Intel C++ Compiler’s command prompt:

  1. Go to Windows 8 UI tile desktop, type in “visual studio 2012 mode”, it will show two items like below and select one to open the command prompt:
    • Intel 64 Visual Studio 2012 mode
    • IA-32 Visual Studio 2012 mode
  2. Follow the instructions here to add [Start] on the Task Bar. Then you can open the Intel C++ Composer XE 2013 command prompt from [Start] menu.

Examples

    1. Matrix multiplication sample – this example contains two simple Windows Store apps in C++ and JavaScript, a C++ Win32 DLL project built with Visual C++, a C++ Win32 DLL project built with Intel C++, a WRL DLL project built with Visual C++, a WRL DLL project built with Intel C++.

      Figure 7 - MatrixSample component diagram

      Steps to build:

      1. Open sample_matrix.sln example
      2. Select “win32|release” configuration
      3. Set “JSMetroApp” as StartUp project and rebuild
      4. Press [F5] to run, you’ll see something below

        Figure 8 – MatrixSample screen capture
      5. Set “CPPMetroApp” as StartUp project and rebuild
      6. Press [F5] to run and a similar screen like above should appear.

  1. Real-time communication sample:
    This example is from Microsoft MSDN and it contains two components - the UI component in JavaScript project, and a core component in C++ WRL DLL project. The Intel C++ compiler can be used to build the C++ WRL DLL project “Microsoft.Samples.SimpleCommunication” with following steps:
    1. Set project “Microsoft.Samples.SimpleCommunication” to use Intel C++
    2. Set the optimization flags you’d like
    3. Rebuild the project
    Note: You will encounter the same build error as noted in above example; use the same workaround to avoid the issue.
  2. A Basic WRL DLL sample project
    This simple WRL project contains an .idl with one simple interface and the class definition/implementation of the simple interface. It can be used as the starting point for a WRL component. The WRL project has been set to use Intel C++ compiler so you will need to the Intel C++ Compiler 13.0 to build. Note: if you only have Intel C++ Compiler 14.0, just change the toolset from "Intel C++ Compiler XE 13.0" to "Intel C++ Compiler XE 14.0" on the "Project Property" 's "General" page.
    This simple WRL project is created using the online WRL project template. It is also very similar to this hybrid MSDN sample. When building the "Release" configuration of this hybrid MSDN sample with Intel C++ Compiler, you will see the link errors below:
    WRLClassLibrary1.exp : error LNK2001: unresolved external symbol _DllCanUnloadNow@0
    WRLClassLibrary1.exp : error LNK2001: unresolved external symbol _DllGetActivationFactory@8
    WRLClassLibrary1.exp : error LNK2001: unresolved external symbol _DllGetClassObject@12
    
    This is the same link error mentioned above. The work-around is:
    • Replace /Qipo with /Qip in the project property “C/C++ > Optimization[IntelC++] > Interprocedural Optimization”

Conclusion

As you already know by now the Intel C++ Composer XE 2013 for Windows and Intel C++ Composer XE 2013 SP1 for Windows do not support Visual Studio 2012 for Windows Store app development in this release. This article has shown you several ways to use Intel C++ Compiler to build some modules or C++ source code in your Windows Store app for experimental purposes. We do hope to hear from you for any new issues or comments or suggestions.

Last but not least, please let us know through Intel® Premier Support or Intel® C++ Compiler forum any issues you encounter when experimenting with the Intel C++ Compiler and Windows Store Apps.

Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.