22

Is there a way to build Windows Store applications with the Mingw toolchain? (And ultimately cross compile them from mingw on Linux, since if it works in one Mingw toolchain it should work in another.)

I guess one requirement is to stick to the API:s allowed in the Windows Store app sandbox, but what other things are there to consider before distribution to the store? XAML? 32 or 64 bit code?

Since Mingw C++ is not link compatible with MSVC++, I assume plain C programs without WRL would be the easiest way to achieve this?

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
  • Thank you for the link to MXE, never heard of that one before... must be the single coolest thing I've seen for a while. – Damon Oct 16 '12 at 09:24
  • @Damon, I thought so too when I saw it the other day, I felt I had to put a link up here so someone else can see it. It's really really cool. :-) – Prof. Falken Oct 16 '12 at 09:36
  • If you try to run it, it can happen that it won't find one of the libraries, just download it from a mirror and put it in the pkg/ directory and the compile can be resumed. @Damon – Prof. Falken Oct 16 '12 at 09:41
  • @Damon, it was ftp://core.ring.gr.jp/pub/graphics/gd/gd-2.0.35.tar.bz2 I had to download manually. – Prof. Falken Oct 16 '12 at 17:52
  • Worked pretty much out of the box for me after running `aptitude` to install 2 missing deps. – Damon Oct 16 '12 at 19:41
  • @Damon, haha, for me it's still building on my netbook after 48 hours :) – Prof. Falken Oct 16 '12 at 20:18

3 Answers3

11

You would need to use the Windows Runtime C++ Template Library (WRL) directly, you wouldn't be able to use C++/CX as Mingw doesn't support it. Other than that, I think you just need the Windows 8 SDK, then you need to configure Mingw to use the headers and libraries. Also, you won't be able to use XAML to describe your user interface, you'll have to manually create your UI in code.

Rather than attempt to write the entire application with mingw and cross compile it with linux, you can write your core libraries with mingw, then write a simple UI wrapper over the libraries using Visual Studio Express (free). That way you can use all the nice stuff like XAML and ref-counted instances.

This is the approach I have taken - using libraries written in C++, and then a separate UI project (using XAML) which references the other libraries. It works well.

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
Mark Ingram
  • 71,849
  • 51
  • 176
  • 230
  • Any particular reason why the Windows 8 SDK would be needed? No MS SDK is needed to build Windows apps for versions <= 7. – Prof. Falken Oct 16 '12 at 09:37
  • 1
    And the page says "The WRL enables you to more easily implement and consume Component Object Model (COM) components." ... but from C you can call COM objects directly, with no WRL wrapper. So I don't see WRL as imperative either, unless you add some evidence for that. Sorry but your answer just left me with more questions. :-) – Prof. Falken Oct 16 '12 at 09:39
  • The Windows 8 SDK is needed if you're going to use WRL, if you're not planning on using WRL to wrap the COM calls, you probably don't need it. – Mark Ingram Oct 16 '12 at 09:42
  • OK, that makes sense. Updated answer slightly. I don't think you can use MSVC++ link libraries from Mingw g++. – Prof. Falken Oct 16 '12 at 09:47
  • 1
    I'm not 100% sure as I've not tried it yet, but I don't think you need to link to any of the WinRT libraries, as they are all accessed via COM. This is now a grey area for me :) – Mark Ingram Oct 16 '12 at 10:11
  • http://www.codeproject.com/Articles/13601/COM-in-plain-C <--- must be something like that + whatever COM modules are necessary to talk to Metro APIs – Prof. Falken Oct 16 '12 at 22:19
  • Edit your question so I can upvote it. I have come to agree 100%. – Prof. Falken Jan 10 '13 at 07:06
  • Still, it would be kind of cool is someone made a "hello world" written entirely with free software for Windows 8/RT/METRO. – Prof. Falken Jan 10 '13 at 10:25
  • 1
    You can throw a look to cppwinrt https://github.com/Microsoft/cppwinrt I get it compiling/linking with mingw64 ... the only problem is, that i need to manual define the UUID for the different interfaces.... which mingw dont know. perhaps someone updates the mingw headers to the windows10 SDK. I dont know how this is working. – Gabor Feb 08 '17 at 21:09
6

MinGW-w64 has experimental support of UWP C runtime distributed with VS2013. C dlls linked with universal VS2013 crt are also can be used with VS2015 and VS2017 UWP toolchains ( UWP project should has "Microsoft Visual C++ 2013 Runtime Package for Windows Universal" as dependency).
MinGW-w64 provides winstorecompat library to replace some forbidden API calls on UWP platform with user defined implementation. winstorecompat should be linked to user's library before linking with system libraries.
Also it's required to build MinGW C dll with custom flag -Wl,--dynamicbase to pass Windows 10 Store Certification Kit security checks and also set appcontainer bit flag to be compatible with Windows 10 Store binary requriements.
Here it's link to sample project I've worked on how to consume plain C MinGW Dll into Windows 10 C# UWP application, PInvoke methods from C dll and pass Certification Kit security checks to be published in Windows Store. I've referenced libVLC WinRT build implementation.

Max Go
  • 2,092
  • 1
  • 16
  • 26
  • Not bad! I like it, I starred your repo. I understand it's your repo since you ask for feedback, but maybe you should state it explicitly in your answer. Some people down vote for self promotion unless it's stated up front. – Prof. Falken Sep 13 '17 at 08:43
  • @Prof.Falken got it, thank you, actually, I more interested if someone will try to use it in real app to be published in Store. Certification Kit doesn't show any issues for sample UWP app bundle, but some others issues can appear as usual... – Max Go Sep 13 '17 at 13:27
  • 1
    I will provide more technical details in a while to the answer. – Max Go Sep 13 '17 at 13:29
3

Take a look at using C++/WinRT with clang compiler instead of MinGW:

https://github.com/Microsoft/cppwinrt
https://moderncpp.com/

"C++/WinRT is a standard C++ language projection for the Windows Runtime implemented solely in header files. It allows you to both author and consume Windows Runtime APIs using any standards-compliant C++ compiler."

"C++/WinRT relies on C++17 language features and as such you need to tell C++ that your project requires the C++17 language standard."

"While Visual C++ continues to be our primary target, we use Clang as our secondary compiler to ensure standard conformance. Many small changes have been made in this update to support Clang builds and to fix correctness bugs that were only found with Clang builds."

Bimo
  • 5,987
  • 2
  • 39
  • 61