如何 link 或包含 winrt 来编译您的项目

HOW to link or well include winrt to compile your project

fatal error: experimental/coroutine: No such file or directory

这是编译器给我的错误 这是 main.cpp

#include <fstream>
#include <iostream>
#include <filesystem>
#include <chrono>

#include <thread>
#include <winrt/windows.ui.viewmanagement.h>
int main (){
    bool running = true;
    winrt::Windows::UI::ViewManagement::UISettings Colsettings;
    auto coloracc = Colsettings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Accent);
    std::cout << coloracc.B;
    if (!std::filesystem::exists("color.inc")) {
        running = false;
    }
    while (running)
    {
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
        std::cout << "aaaaaaaaaaa";
    }
    
}

这里是task.json

{
"version": "2.0.0",
"tasks": [
    {
        "type": "process",
        "label": "C/C++: g++.exe build active file",
        "command": "C:\msys64\mingw64\bin\g++.exe",
        "args": [
            "-fdiagnostics-color=always",
            "-std=c++23",
            "-g",
            "${file}",
            "-I",
            "C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/cppwinrt",
            "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include",
            "-o",
            "${fileDirname}\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build",
        "detail": "compiler: C:\msys64\mingw64\bin\g++.exe"
    }
]

}

我想解决办法是改变 tasks.json 我在网上冲浪,在 vscode

中没有找到告诉我如何使用 winrt 的文章

谢谢

    C:\msys64\mingw64\bin\clang++.exe -std=c++17 -g *.cpp -I "C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/cppwinrt" -I "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include" -I "C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt" -o "C:\behe\My_life\programmation\rainmeter c++ app simple ii guess\main.exe"
In file included from main.cpp:2:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/fstream:9:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/yvals_core.h:394:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:58:
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vadefs.h:61:33: error: expected ';' after top level declarator
        typedef unsigned __int64  uintptr_t;
                                ^
                                ;
In file included from main.cpp:2:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/fstream:9:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/yvals_core.h:394:
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:96:1: error: C++ requires a type specifier for all declarations
_CRT_BEGIN_C_HEADER
^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:69:9: note: expanded from macro '_CRT_BEGIN_C_HEADER'
        __pragma(pack(push, _CRT_PACKING)) \
        ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:96:1: error: use of undeclared identifier 'push'
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:69:23: note: expanded from macro '_CRT_BEGIN_C_HEADER'
        __pragma(pack(push, _CRT_PACKING)) \
                      ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:96:1: error: expected ';' after top level declarator
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:70:9: note: expanded from macro '_CRT_BEGIN_C_HEADER'
        extern "C" {
        ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:193:29: error: expected ';' after top level declarator
    typedef unsigned __int64 size_t;
                            ^
                            ;
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:228:22: error: 'short wchar_t' is invalid
    typedef unsigned short wchar_t;
                     ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:228:5: warning: typedef requires a name [-Wmissing-declarations]
    typedef unsigned short wchar_t;
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:252:42: error: unknown type name 'size_t'
        template <typename _CountofType, size_t _SizeOfArray>
                                         ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:366:51: error: unknown type name 'uintptr_t'; did you mean 'intptr_t'?
        void __cdecl __security_check_cookie(_In_ uintptr_t _StackCookie);
                                                  ^~~~~~~~~
                                                  intptr_t
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:195:30: note: 'intptr_t' declared here
    typedef __int64          intptr_t;
                             ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:367:67: error: unknown type name 'uintptr_t'; did you mean 'intptr_t'?
        __declspec(noreturn) void __cdecl __report_gsfailure(_In_ uintptr_t _StackCookie);
                                                                  ^~~~~~~~~
                                                                  intptr_t
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:195:30: note: 'intptr_t' declared here
    typedef __int64          intptr_t;
                             ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:371:8: error: unknown type name 'uintptr_t'; did you mean 'intptr_t'?
extern uintptr_t __security_cookie;
       ^~~~~~~~~
       intptr_t
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:195:30: note: 'intptr_t' declared here
    typedef __int64          intptr_t;
                             ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:379:1: error: C++ requires a type specifier for all declarations
_CRT_END_C_HEADER
^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:74:9: note: expanded from macro '_CRT_END_C_HEADER'
        __pragma(pack(pop))
        ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:379:1: error: use of undeclared identifier 'pop'
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:74:23: note: expanded from macro '_CRT_END_C_HEADER'
        __pragma(pack(pop))
                      ^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:379:18: error: expected ';' after top level declarator
_CRT_END_C_HEADER
                 ^
                 ;
In file included from main.cpp:2:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/fstream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/istream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ostream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ios:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/xlocnum:13:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/cstdio:12:
In file included from C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/stdio.h:13:
In file included from C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/corecrt_wstdio.h:13:
C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/corecrt_stdio_config.h:35:10: error: Unsupported architecture
        #error Unsupported architecture
         ^
In file included from main.cpp:2:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/fstream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/istream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ostream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ios:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/xlocnum:15:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/iterator:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/iosfwd:14:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/cwchar:13:
In file included from C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/wchar.h:25:
C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/sys/stat.h:17:1: error: C++ requires a type specifier for all declarations
_CRT_BEGIN_C_HEADER
^
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:69:9: note: expanded from macro '_CRT_BEGIN_C_HEADER'
        __pragma(pack(push, _CRT_PACKING)) \
        ^
In file included from main.cpp:2:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/fstream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/istream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ostream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ios:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/xlocnum:15:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/iterator:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/iosfwd:14:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/cwchar:13:
In file included from C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/wchar.h:25:
C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/sys/stat.h:17:1: error: use of undeclared identifier 'push'
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:69:23: note: expanded from macro '_CRT_BEGIN_C_HEADER'
        __pragma(pack(push, _CRT_PACKING)) \
                      ^
In file included from main.cpp:2:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/fstream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/istream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ostream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ios:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/xlocnum:15:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/iterator:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/iosfwd:14:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/cwchar:13:
In file included from C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/wchar.h:25:
C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/sys/stat.h:17:1: error: expected ';' after top level declarator
C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/vcruntime.h:70:9: note: expanded from macro '_CRT_BEGIN_C_HEADER'
        extern "C" {
        ^
In file included from main.cpp:2:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/fstream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/istream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ostream:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/ios:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/xlocnum:15:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/iterator:11:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/iosfwd:14:
In file included from C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/include/cwchar:13:
In file included from C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/wchar.h:25:
C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/sys/stat.h:27:5: error: unknown type name '_ino_t'
    _ino_t         st_ino;
    ^
C:/Program Files (x86)/Windows Kits/10/Include/10.0.22000.0/ucrt/sys/stat.h:34:5: error: unknown type name '__time32_t'
    __time32_t     st_atime;
    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.

这是问题 clang++ 给我的错误 g++ 给我大约 447 个错误所以是的我不知道我应该做什么

所以我尝试使用 cl.exe 这是编译器错误

    cl.exe /std:c++17 /Zi /EHsc /nologo /Fe: "C:\behe\My_life\programmation\rainmeter c++ app simple ii guess\main.exe" "C:\behe\My_life\programmation\rainmeter c++ app simple ii guess\main.cpp"
main.cpp
main.obj : error LNK2019: unresolved external symbol _WINRT_IMPL_SetErrorInfo@8 referenced in function "struct winrt::hresult __cdecl winrt::impl::get_runtime_activation_factory<struct winrt::Windows::Foundation::IActivationFactory>(struct winrt::param::hstring const &,void * *)" (??$get_runtime_activation_factory@UIActivationFactory@Foundation@Windows@winrt@@@impl@winrt@@YA?AUhresult@1@ABUhstring@param@1@PAPAX@Z)
main.obj : error LNK2019: unresolved external symbol _WINRT_IMPL_GetErrorInfo@8 referenced in function "struct winrt::hresult __cdecl winrt::impl::get_runtime_activation_factory<struct winrt::Windows::Foundation::IActivationFactory>(struct winrt::param::hstring const &,void * *)" (??$get_runtime_activation_factory@UIActivationFactory@Foundation@Windows@winrt@@@impl@winrt@@YA?AUhresult@1@ABUhstring@param@1@PAPAX@Z)
main.obj : error LNK2019: unresolved external symbol _WINRT_IMPL_SysAllocString@4 referenced in function "public: virtual int __stdcall winrt::impl::error_info_fallback::GetDescription(wchar_t * *)" (?GetDescription@error_info_fallback@impl@winrt@@UAGHPAPA_W@Z)
main.obj : error LNK2019: unresolved external symbol _WINRT_IMPL_SysFreeString@4 referenced in function "public: static void __cdecl winrt::impl::bstr_traits::close(wchar_t *)" (?close@bstr_traits@impl@winrt@@SAXPA_W@Z)
main.obj : error LNK2019: unresolved external symbol _WINRT_IMPL_SysStringLen@4 referenced in function "public: __thiscall winrt::hresult_error::hresult_error(struct winrt::hresult,struct winrt::take_ownership_from_abi_t)" (??0hresult_error@winrt@@QAE@Uhresult@1@Utake_ownership_from_abi_t@1@@Z)
C:\behe\My_life\programmation\rainmeter c++ app simple ii guess\main.exe : fatal error LNK1120: 5 unresolved externals
{
            "type": "cppbuild",
            "label": "C/C++: cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "WindowsApp.lib",
                "/std:c++17",
                "/Zi",
                "/EHsc",
                "/nologo",
                "/Fe:",
                "${fileDirname}\${fileBasenameNoExtension}.exe",
                "*.cpp"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build",
            "detail": "compiler: cl.exe"
        }

所以我使用了 Microsoft 编译器并且它工作正常也许我会尝试使用 cmake 因为我猜项目会变得更大