【问题标题】:C++/WinRT, part of Windows SDK 17134 is not compatible with Visual Studio 15.8 Preview 3C++/WinRT,Windows SDK 17134 的一部分与 Visual Studio 15.8 Preview 3 不兼容
【发布时间】:2018-10-29 01:52:19
【问题描述】:

尝试编译以下代码:

#include <winrt/base.h>

int main() {}

使用以下编译器选项:

/permissive- /std:c++latest

最近发布的 Visual Studio 15.8 Preview 3.0 会导致以下编译错误:

1>------ Build started: Project: test1, Configuration: Debug x64 ------
1>Source.cpp
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2185): error C3861: 'from_abi': identifier not found
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2185): note: This diagnostic occurred in the compiler generated function 'conditional<_Test,T,_Ty2>::type winrt::impl::as(From *)'
1>        with
1>        [
1>            _Ty2=winrt::com_ptr<T>
1>        ]
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2209): error C3861: 'from_abi': identifier not found
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2209): note: This diagnostic occurred in the compiler generated function 'conditional<_Test,T,_Ty2>::type winrt::impl::try_as(From *) noexcept'
1>        with
1>        [
1>            _Ty2=winrt::com_ptr<T>
1>        ]
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(3850): error C3861: 'from_abi': identifier not found
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(3873): note: see reference to class template instantiation 'winrt::weak_ref<T>' being compiled
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(2984): note: see reference to class template instantiation 'winrt::com_ptr<ILanguageExceptionErrorInfo2>' being compiled
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(3054): note: see reference to class template instantiation 'winrt::com_ptr<IRestrictedErrorInfo>' being compiled
1>c:\program files (x86)\microsoft visual studio\preview\professional\vc\tools\msvc\14.15.26608\include\type_traits(616): note: see reference to class template instantiation 'std::basic_string_view<wchar_t,std::char_traits<wchar_t>>' being compiled
1>c:\program files (x86)\microsoft visual studio\preview\professional\vc\tools\msvc\14.15.26608\include\xstring(2124): note: see reference to class template instantiation 'std::is_convertible<const _StringViewIsh &,std::basic_string_view<wchar_t,std::char_traits<wchar_t>>>' being compiled
1>        with
1>        [
1>            _StringViewIsh=const wchar_t *
1>        ]
1>c:\program files (x86)\microsoft visual studio\preview\professional\vc\tools\msvc\14.15.26608\include\xstring(2122): note: see reference to variable template 'const bool conjunction_v<std::is_convertible<wchar_t const * const &,std::basic_string_view<wchar_t,std::char_traits<wchar_t> > >,std::negation<std::is_convertible<wchar_t const * const &,wchar_t const *> > >' being compiled
1>c:\program files (x86)\microsoft visual studio\preview\professional\vc\tools\msvc\14.15.26608\include\xstring(2281): note: see reference to alias template instantiation '_Is_string_view_ish<const wchar_t*>' being compiled
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\cppwinrt\winrt\base.h(6308): error C3861: 'to_abi': identifier not found
1>Done building project "test1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

有什么解决办法吗?

【问题讨论】:

  • 您是否有受支持的 Windows SDK 版本(版本 10.0.17134.0(Windows 10,版本 1803)或更高版本)?请参阅documentation 获取from_abi
  • 我可以重现这个问题。即使没有/permissive-,C++/WinRT 的 17134 版本似乎与 VS 2017(15.8 更新预览 3)不兼容...可能是编译器问题,所以我会 ping 相关团队。
  • 另请注意,您应该在 VS 2017 中使用 /std:c++17 而不是 /std:c++latest。您只需要对 C++/WinRT 的 C++17 支持,而不是未来的某些 C++20。跨度>
  • 对于 C++/WinRT 可能是这样,但它不是程序中唯一的组件。其他部分可能需要 C++17 中不可用的功能
  • 2018 年 8 月 14 日发布的 Visual Studio 2017 15.8.0 也会出现此问题。answer 暗示这是一个需要通过 SDK 更新解决的问题,以便应该不足为奇。我只是留下这些信息,以防将来不使用 Visual Studio Preview 的访问者也遇到这个问题(比如我自己)。

标签: c++ c++-winrt


【解决方案1】:

这是一个已知问题,将在未来的 Windows 10 SDK 更新中解决。

您可以通过完全关闭一致性模式 (/permissive-) 来解决此问题,或者 - 通过添加到 其他选项 /Zc:twoPhase- 以禁用 two-phase name lookup 来保持它。

您应该在 VS 2017 for C++/WinRT 中使用 /std:c++17 而不是 /std:c++latest 来启用 C++17,而无需选择未来的草案更改。

更新:此问题已使用 Windows 2018 年 10 月 10 日更新 SDK (17763) 解决。

【讨论】:

  • /permissive- /Zc:twoPhase- /std:c++latest 的组合似乎可以工作,以防您在编译单元中需要实验性功能。我不清楚为什么 C++/WinRT 不这样做,因为它依赖/提供可用的协程,而协程不是 C++17 的一部分。如果你知道的话,这里有什么交易?
  • C++17 的 C++/WinRT 标头需要内联命名空间,否则只需要 C++14 通用 constexpr 即可构建。强烈建议使用协同例程,但它实际上并不是 C++11、C++14 或 C++17 的一部分。它通过/await 标志启用。
  • /permissive- 已经存在 - /Zc:twoPhase- 工作了。
  • 这里的“破坏”到底是什么?
  • @ChuckWalbourn 关闭一致性模式会产生破坏性影响,例如操作员名称将停止工作。
【解决方案2】:

我做了一个小补丁来解决这个问题。它添加了几个前向声明,因此可以通过两阶段查找和缺少的 template 关键字找到必要的名称。

C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\cppwinrt\winrt\base.h

2171a2172,2189
>     template <typename D, typename I, typename Enable = void>
>     struct producer;
> }
> 
> WINRT_EXPORT namespace winrt
> {
>     template <typename D, typename I>
>     D* from_abi(I const& from) noexcept;
> 
>   template <typename I, typename D, std::enable_if_t<std::is_base_of_v<Windows::Foundation::IUnknown, I>>* = nullptr>
>     impl::abi_t<I>* to_abi(impl::producer<D, I> const* from) noexcept;
> 
>     template <typename I, typename D, std::enable_if_t<std::is_base_of_v< ::IUnknown, I>>* = nullptr>
>     impl::abi_t<I>* to_abi(impl::producer<D, I> const* from) noexcept;
> }
> 
> namespace winrt::impl
> {
6244c6262
<     template <typename D, typename I, typename Enable = void>
---
>     template <typename D, typename I, typename Enable>
6353c6371
<     template <typename I, typename D, std::enable_if_t<std::is_base_of_v<Windows::Foundation::IUnknown, I>>* = nullptr>
---
>     template <typename I, typename D, std::enable_if_t<std::is_base_of_v<Windows::Foundation::IUnknown, I>>*>
6359c6377
<     template <typename I, typename D, std::enable_if_t<std::is_base_of_v< ::IUnknown, I>>* = nullptr>
---
>     template <typename I, typename D, std::enable_if_t<std::is_base_of_v< ::IUnknown, I>>*>
7189c7207
<             return root_implements_type::get_weak<D>();
---
>             return root_implements_type::template get_weak<D>();

【讨论】:

    猜你喜欢
    • 2018-04-19
    • 2016-07-22
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多