Solved cppwinrt library usage refuses to compile in Qt projects
-
Microsoft have a C++ UWP library called cppwinrt, this provides a modern C++ platform for interacting with the Windows Runtime without faffing about with the old WRL templates and COM objects. It's a header only library and as such setup should be simple.
https://github.com/Microsoft/cppwinrt
I've add the library header directory to the INCLUDEPATH of a template MSVC2015 QWidgets project and have included the relevant cppwinrt header files. I have installed all the requires Windows kits however I am unable to compile a project without getting the error.
/Windows Kits/10/include/10.0.15063.0/um/WindowsNumerics.impl.(27): Parse error at "winrt"
Unfortuantely my knowledge of Makefiles is lacking so i'm unsure what could be causing this issue. I can compile and use the library fine in Visual Studio. From a quick look at the cppwinrt library source it relies heavily on macros which redefine macros that are within the WindowsKits. Could it potentially be an include order issue?
Full compile log below:
Example Project:
https://ufile.io/iasrp -
@sebkajeka Can you show your pro file?
-
It's included in the project but for ease:
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = untitled TEMPLATE = app QMAKE_CXXFLAGS += /std:c++latest # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 LIBS += -lwindowsapp SOURCES += main.cpp\ mainwindow.cpp INCLUDEPATH += $$PWD/10.0.15063.0 HEADERS += mainwindow.h FORMS += mainwindow.ui
-
@sebkajeka I think for WinRT you need Qt for WinRT (you can install it easily using Qt Maintenance Tool).
-
@jsulm This paradigm differs from Qt for WinRT as it allows you to use UWP (WinRT) API's in a non-sandboxed C++ application.
-
@sebkajeka /Windows Kits/10/include/10.0.15063.0/um/WindowsNumerics.impl.(27): Parse error at "winrt" - what is actually at line 27 in that file?
-
Upon inspection of base.h I assume this has something to do with the WINDOWS_NUMERICS_BEGIN_NAMESPACE which is referenced in line 27 of WindowsNumerics.impl.h and is redefined in base.h as
#define _WINDOWS_NUMERICS_BEGIN_NAMESPACE_ namespace winrt::Windows::Foundation::Numerics
The issue lies with the definition of the macros
-
This is caused by the Qt MOC compiler and cppwinrt headers.
To build successfully wrap the cppwinrt #includes in:
#ifndef Q_MOC_RUN
#endif