【发布时间】:2018-08-12 14:19:27
【问题描述】:
我在 VS 2017 中创建了一个新的 C++ 动态 DLL 项目(非 UWP!)。无法使用 /ZW (C++/CX) 编译它。为什么不?请不要回答“制作 UWP 项目”,这不是这里的问题。我可以制作编译得很好的 UWP 项目。我已经看到了很多不是 UWP 目标的 C++/CX 项目的示例代码,它们只是不能在 VS 2017 中编译,我想知道为什么不能。除非答案是“没有 UWP 就无法编译 C++/CX 项目”,我没有看到任何证据。
第 1 步:制作新项目。
编译。编译正常。
第 2 步:打开 C++/常规/使用 Windows 运行时扩展 (/ZW)。关闭 /Gm。
编译。
1>c1xx : warning C4199: two-phase name lookup is not supported for C++/CLI, C++/CX, or OpenMP; use /Zc:twoPhase-
1>c:\users\efrazer\source\repos\dll2\dll2\stdafx.cpp : fatal error C1107: could not find assembly 'platform.winmd': please specify the assembly search path using /AI or by setting the LIBPATH environment variable
第 3 步:嗯。阅读它。在 C++ 设置中打开一致性模式 = NO
编译。
1>c:\users\efrazer\source\repos\dll2\dll2\stdafx.cpp : fatal error C1107: could not find assembly 'platform.winmd': please specify the assembly search path using /AI or by setting the LIBPATH environment variable
第 4 步:嗯。在线阅读更多关于寻找正确路径的信息。在 C++ 设置中将其他 #using 目录设置为:
$(VCIDEInstallDir)vcpackages;
$(WindowsSDKDir)UnionMetadata;
C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Annotate
d;
编译。
1>------ Build started: Project: Dll2, Configuration: Debug Win32 ------
1>stdafx.cpp
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.12.25827\include\vccorlib.h(965): error C3624: 'System::Attribute': use of this type requires a reference to assembly 'mscorlib'
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.12.25827\include\vccorlib.h(965): note: This diagnostic occurred while importing type 'Windows::Foundation::Metadata::DefaultAttribute ' from assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null'.
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.12.25827\include\vccorlib.h(1706): note: see reference to class template instantiation 'Platform::Array<unsigned char,1>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.12.25827\include\vccorlib.h(965): error C2373: 'Windows::Foundation::Metadata::DefaultAttribute::DefaultAttribute': redefinition; different type modifiers
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.12.25827\include\vccorlib.h(965): note: This diagnostic occurred while importing type 'Windows::Foundation::Metadata::DefaultAttribute ' from assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null'.
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.12.25827\include\vccorlib.h(965): error C2337: 'Default': attribute not found
1>Done building project "Dll2.vcxproj" -- FAILED.
第 5 步:在线查找错误。我查找的所有内容都告诉我,我不能混合 UWP code with C++ native code 或类似的东西。
我错过了一些简单的事情吗?这应该没那么难吧?
【问题讨论】: