Using Boost Libraries in Windows Store and Phone Applications

RATE THIS

18 Jul 2014 5:30 AM

Boost contains a
lot
 of high quality cross platform C++ libraries. Some of the libraries in Boost use APIs that aren’t available in Windows Store and Phone applications. To help improve the experience Microsoft’s been working on enabling some
of the Boost libraries.

We’ve made improvements to the Boost build system to support targeting the Windows Runtime for Windows Store and Phone. Also we’ve made changes to make the following Boost libraries work for Windows Store and Phone:
system, chrono, date_time, smart_ptr, signals2, and thread. In addition to these Boost libraries, many others don’t use any banned APIs and work fine. This post shows how you can build and utilize portions of Boost in your Windows applications.

Download and Setup Boost Sources

Here are the steps to download and setup the Boost sources for building. Boost has moved over to GitHub,
now using Git submodules. More detailed information about modular Boost can be located here.

  • Clone Boost and setup for building. Please note this is a one-time operation that will take some time as it brings down all of the Boost sources. Throughout this post it is assumed you cloned into C:\boost.

  • Add the build tool, b2, to your Path environment variable. If you are using PowerShell something like following works.

    • $env:Path += ";C:\boost";
  • A few of the changes for enabling the Windows Runtime haven’t migrated to into the ‘master’ branches or are still pending a merge. For these you will need to checkout the ‘develop’ branch or pull from my private branch
    containing the necessary changes.

Boost.Build

  • cd C:\boost\tools\build
  • git checkout develop

Boost.Config

Boost.Thread – optional only needed if going to use thread or a library that depends on it

Building for Windows Store and Phone

With the latest Boost sources and your repositories setup you are now ready for building. If the Boost library/libraries you are interested in using are header file only, like Boost.Signals2 for example, then you don’t
need to build and can entirely skip this step. Of the libraries we’ve enabled and verified, system, chrono, thread, and date_time are the only ones that require building.

To enable easily targeting the Windows Runtime a new feature called ‘windows-api’ has been added to the Boost build system. It accepts the values ‘store’, ‘phone’, and defaults to ‘desktop’ if not specified.

To build go to the build directory under the library you wish to use, for example to build Boost.Thread 32 bit debug for Windows 8.1 Store for static linking use the following command:

  • cd C:\boost\libs\thread\build
  • b2 toolset=msvc-12.0 link=static windows-api=store

About toolsets and targeting, the toolset you specify determines which Windows version you are targeting:

  • Windows 8.0:                toolset=msvc-11.0 windows-api=store
  • Windows 8.1:                toolset=msvc-12.0 windows-api=store
  • Windows Phone 8.0:     toolset=msvc-11.0 windows-api=phone
  • Windows Phone 8.1:     toolset=msvc-12.0 windows-api=phone

The built-in Boost features variant, address-model, architecture, link can be used to produce debug/release, x86/x64/arm, and static/shared binaries. For example the following builds the release configuration, with
static linking for the ARM architecture:

b2 toolset=msvc-12.0 variant=release link=static architecture=arm windows-api=store

More detailed information can be found in the Boost.Build documentation.

Once built, the binaries are output under the bin.v2 folder. The exact location is dependent on the options used and the name of the library built. For the command from before used to build Boost.Thread the binaries
are located under:

C:\boost\bin.v2\libs\thread\build\msvc-12.0\debug\link-static\threading-multi\windows-api-store\

Please note Visual Studio 2013 didn’t include vcvarsphone setup scripts so you won’t be able to target Phone 8.1 out of the box. With this blog post I’ve included phone setup scripts that can be used when targeting
Windows Phone 8.1. To setup them up create the folders called WPSDK\WP81 under the VC Visual Studio installation directory, C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\, and copy the phone setup script files in.

How to use in an Application

With all the setup and building complete, using in an application is just the same as with any other C++ library. Setup the include path by adding C:\boost\. If the Boost library you’re using isn’t header file only
then link to the lib and add the dll to the project (if not using static linking), making sure to set the ‘Content’ property to true so it is picked up for application deployment.

To help illustrate how to setup and use in an application, at the end of this post, I’ve included a simple sample Windows 8.1 Store application that utilizes the thread and signal2 libraries. The sample creates a simple
signal with multiple slots using Boost threads in different ways. The sample assumes you cloned Boost into the C:\boost directory and built static linking for Boost.Thread, Boost.Date_Time, Boost.Chrono, and Boost.System, if this isn’t the case then you will
need to update the include and library paths. Included with the sample also are the vcvars setup scripts for targeting Windows Phone 8.1.

Feedback and How to Enable More Boost Libraries

For your next Windows Store and Phone application try using and let us know how it goes. Several individuals are already trying it out and Spotify is using several of the libraries in their Windows
Phone application
.

Not all of the libraries in Boost work yet in Windows Store and Phone, but the work we’ve done makes it easier to build and replace or update banned APIs. If one of the Boost libraries you want to use doesn’t work,
depending on the banned API it might be easy to replace. We’ve added several new Boost.Predef,
macros. By including <boost/predef/platform.h> you can use the BOOST_PLAT_WINDOWS_DESKTOP and BOOST_PLAT_WINDOWS_RUNTIME macros to test which platform is being targeted. For example if a call to WaitForSingleObject (only allowed in desktop) is used, you could
replace it with WaitForSingleObjectEx by checking the macro for the Windows Runtime:

#include <boost/predef/platform.h>

...

#if BOOST_PLAT_WINDOWS_RUNTIME 

    WaitForSingleObjectEx(handle, INFINITE, FALSE);

#else

    WaitForSingleObject(handle, INFINITE);

#endif

For more complex examples of API replacement you can take a look at the changes I made for Boost.Thread.

We are interested in hearing your feedback. What Boost libraries do you care about or what to use in your Windows Store and Phone applications?

原文地址:http://blogs.msdn.com/b/vcblog/archive/2014/07/18/using-boost-libraries-in-windows-store-and-phone-applications.aspx

Using Boost Libraries in Windows Store and Phone Applications的更多相关文章

  1. Windows Store Javascript项目使用高德地图、谷歌地图、百度地图API

    原文 Windows Store Javascript项目使用高德地图.谷歌地图.百度地图API 在Win8 Store 项目中可以使用的地图主要有微软的Bing Map,目前高德地图sdk也支持Wi ...

  2. 在桌面程序上和Metro/Modern/Windows store app的交互(相互打开,配置读取)

    这个标题真是取得我都觉得蛋疼..微软改名狂魔搞得我都不知道要叫哪个好.. 这边记录一下自己的桌面程序跟windows store app交互的过程. 由于某些原因,微软的商店应用的安全沙箱导致很多事情 ...

  3. Could not find the following Boost libraries: boost_python3

    安装Boost.NumPy时报错: CMake Error at /usr/share/cmake/Modules/FindBoost.cmake:1794 (message): Unable to ...

  4. kiosk-mode,免密码登陆, sideload Windows Store apps 等

    MVVM带来的性能问题及其解决方案  MVVM 和语言性能提示:https://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/mt628050. ...

  5. SQLite in Windows Store Apps

    Using SQLite in Windows Store Apps : https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Using-SQL ...

  6. 【Win10 UWP】URI Scheme(一):Windows Store协议的解析和使用

    协议是Windows Phone和Windows Store应用的一个重要特点,可以做到在不同应用之间进行互相呼起调用.小小协议,学问大着呢.我打算写几篇关于协议在UWP中使用的文章. 这一讲的主要对 ...

  7. Issues I encountered when building Windows Store apps on a new laptop

    I took over my beloved wives samsung ativ book 9 recently as her first job granted her a brandnew su ...

  8. Windows Store Apps, Error: The certificate specified has expired.(转)

    Windows Store Apps, Error: The certificate specified has expired. 0 comments|Posted on October 7th, ...

  9. Windows Store App 过渡动画

    Windows Store App 过渡动画     在开发Windows应用商店应用程序时,如果希望界面元素进入或者离开屏幕时显得自然和流畅,可以为其添加过渡动画.过渡动画能够及时地提示用户屏幕所发 ...

随机推荐

  1. JS function的定义方法,及function对象的理解。

    废话篇: 今天看到了Function的内容,各种晕,各种混淆有木有.简直是挑战个人脑经急转弯的极限啊.不过,最终这一难题还是被我攻克了,哇咔咔.现在就把这东西记下来,免得到时候又忘了就悲催了.... ...

  2. UVa 10391 (水题 STL) Compound Words

    今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...

  3. UVa 10161 Ant on a Chessboard

    一道数学水题,找找规律. 首先要判断给的数在第几层,比如说在第n层.然后判断(n * n - n + 1)(其坐标也就是(n,n)) 之间的关系. 还要注意n的奇偶.  Problem A.Ant o ...

  4. HDU 5371 Hotaru's problem (Manacher,回文串)

    题意:给一个序列,找出1个连续子序列,将其平分成前,中,后等长的3段子序列,要求[前]和[中]是回文,[中]和[后]是回文.求3段最长为多少?由于平分的关系,所以答案应该是3的倍数. 思路:先Mana ...

  5. HDU 1548 A strange lift 奇怪的电梯(BFS,水)

    题意: 有一座电梯,其中楼层从1-n,每层都有一个数字k,当处于某一层时,只能往上走k层,或者下走k层.楼主在a层,问是否能到达第b层? 思路: 在起点时只能往上走和往下走两个选择,之后的每层都是这样 ...

  6. C++ 编写Windows service

    最近实现一个windows server端守护进程启动服务功能(c++实现),遇到了一些问题,记录一下 1. 启动Service实现代码: int _tmain(int argc, TCHAR* ar ...

  7. java jodd框架介绍及使用示例

    Jodd是一个普通开源Java包.你可以把Jodd想象成Java的"瑞士军刀",不仅小,锋利而且包含许多便利的功能.Jodd 提供的功能有:  提供操作Java bean,  可以 ...

  8. 【转】使用Python的IDE:Eclipse+PyDev

    原文网址:http://www.crifan.com/try_with_python_ide_eclipse_pydev/ 之前已经介绍过了一些基本知识: [整理][多图详解]如何在Windows下开 ...

  9. hadoop——配置eclipse下的map-reduce运行环境 1

    1.通过修改实例模板程序来实现自己的map-reduce: 为了让示例程序run起来: 1)安装eclipse 2)安装map-reduce的eclipse插件 eclipse的map-reduce插 ...

  10. App中嵌入网页浏览器

    TOWebViewController 插件 NSURL *url =[NSURL URLWithString:@"http://192.168.1.134:8180/Home/IndexP ...