【发布时间】: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 的访问者也遇到这个问题(比如我自己)。