Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Qt project with VS C++ Compiler 15.0 with C++17 to use WinRT APIs

I would like to use libraries available via WinRT API (like these) from my UWP application created using Qt 5.9.2 for UWP 64bit (MSVC 2017). I got Visual Studio Build Tool 2017 v15.5.7 installed on my machine. Windows 10 is my OS.

Now, I have set up a kit as presented below.

UWP Kit setup

Then, in .pro file, I have added:

SOURCES += main.cpp

INCLUDEPATH += $$PWD/cppwinrt/10.0.16299.0/
DEPENDPATH += $$PWD/cppwinrt/10.0.16299.0/

I got cppwinrt from GitHub rep.

I just added some lines in main.cpp to test proper compilation:

#include <QCoreApplication>
#include <winrt/Windows.Devices.WiFi.h>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    WiFiAdapter wiFiAdapter;

    return a.exec();
}

After running qmake and build, I am getting this error:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.12.25827\include\optional(15): fatal error C1189: #error: class template optional is only available with C++17.

Windows documentation clearly states that since v15.3 (once again, I have 15.5.7) C++ compiler accepts the /std:c++17 flag. I have tried to pass it by adding one of these lines to .pro file:

CONFIG += c++1z
# Or
QMAKE_CXXFLAG=/std:c++17

None of them helped.....

This is the detailed build command run by compiler:

cl -c -nologo -FS -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zi -MDd -GR -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc /Fddebug\uwp-test.vc.pdb -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQ_BYTE_ORDER=Q_LITTLE_ENDIAN -DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP -DWINAPI_PARTITION_PHONE_APP=1 -DX64 -D__X64__ -D__x64__ -DQT_DEPRECATED_WARNINGS -DQT_CORE_LIB -I..\uwp-test -I. -I..\ne-patient-app-libraries\cppwinrt\10.0.16299.0 -I..\..\..\..\Qt\5.9.2\winrt_x64_msvc2017\include -I..\..\..\..\Qt\5.9.2\winrt_x64_msvc2017\include\QtCore -Idebug -I..\..\..\..\Qt\5.9.2\winrt_x64_msvc2017\mkspecs\winrt-x64-msvc2017 -Fodebug\ @C:\Users\NEUROE~2\AppData\Local\Temp\main.obj.11672.15.jom

What am I missing? What could solve the problem? Thank you!

like image 681
Paweł Skorupiński Avatar asked Mar 07 '23 19:03

Paweł Skorupiński


1 Answers

You want QMAKE_CXXFLAGS *= /std:c++17 - i.e. _CXXFLAGS not _CXXFLAG

The *= means add it if it's not there already.

like image 111
gremwell Avatar answered Apr 06 '23 17:04

gremwell