how to compile a VS 2017 C++/CX project
Asked Answered
P

1

6

I make a new C++ Dynamic DLL project (non UWP!) in VS 2017. Can’t get it to compile with /ZW (C++/CX). Why not? Please, don't answer "make a UWP project", that's not the question here. I can make UWP projects that compile just fine. I have seen a lot of sample code out there for C++/CX projects that are not UWP targets, they just don't compile in VS 2017 and I want to know why not. Unless the answer IS "C++/CX projects don't compile without UWP", which I see no evidence for.

Step 1: Make new project.

Compile. Compiles fine.

Step 2: Turn on C++/General/Consume Windows Runtime Extension (/ZW). Turn off /Gm.

Compile.

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

Step 3: Ungh. Read up about it. Turn conformance mode = NO in C++ settings

Compile.

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

Step 4: Ungh. Read more online about finding the right paths. Set additional #using directories in C++ settings to:

$(VCIDEInstallDir)vcpackages;
$(WindowsSDKDir)UnionMetadata;
C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Annotate

d;

Compile.

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.

Step 5: look up error online. Everything I look up is telling me I can’t mix UWP code with C++ native code or some such.

Am I missing something easy? This shouldn’t be so difficult, right?

Phosphorescent answered 4/3, 2018 at 23:59 Comment(0)
P
8

I figured it out last night. The #using paths have to be exactly right or the compiler will cough up errors. It's no more magical than that.

For compiler v141 (Visual Studio 2017), targeting Windows SDK Version 16299, the paths have to be:

$(VCIDEInstallDir)vcpackages;
$(WindowsSDKDir)UnionMetadata\10.0.16299.0

that's it! Then it compiles! And I verified being able to step through it w/ the debugger.

Phosphorescent answered 5/3, 2018 at 18:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.