Compiling C++/CX on the command line

妖精的绣舞 提交于 2019-12-04 17:06:50

UPDATE: Apparently this bug has been fixed in VS2015 Update 1, I have not been able to test myself yet though.

As it turns out some command line parameters are missing from the documentation mentioned in the question, here is the full command line required to compile a small program:

cl /ZW
   /ZW:nostdlib
   /D WINAPI_FAMILY=WINAPI_FAMILY_APP
   /D __WRL_NO_DEFAULT_LIB__
   /Gm-
   /EHsc
   /MDd
   /FU"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\store\references\platform.winmd"
   /FU"C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\1.0.0.0\Windows.Foundation.FoundationContract.winmd"
   /FU"C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\1.0.0.0\Windows.Foundation.UniversalApiContract.winmd"
   smurf.cpp
   /link /SUBSYSTEM:CONSOLE

Where smurf.cpp contains:

using namespace Platform;

int main(Platform::Array<Platform::String^>^ args)
{
    Platform::Details::Console::WriteLine("This is a C++/CX program.");
}

Will successfully print:

C:\Users\Mikael>smurf.exe
This is a C++/CX program.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!