Search code examples
c#c++.netnativecorert

How do I build using the native corert preview?


I have tried to get a .NET core 2.0 console application targeting win-x86 to build using the CoreRT ilc compiler and Microsoft linker.

So far I downloaded the latest version of the CoreRT libraries and successfully built a preview using the release target as of commit C7781A90F00645F6BD06EF57E5D3FD879FE3E9A0.

I added build scripts rd.xml, ilc.rsp, and link.rsp, but I keep getting the message from ilc:


Error: Target architecture is not supported
Internal.CommandLine.CommandLineException: Target architecture is not supported
   at ILCompiler.Program.Run(String[] args)
   at ILCompiler.Program.Main(String[] args)

I was able to resolve the issue with the architecture, but now it is failing with a missing file reference:

C:\
cd \testapp
call "..\corert\bin\Windows_NT.x64.Release\tools\ilc.exe" ".\ilc.rsp"

Output:

Error: [TEMPORARY EXCEPTION MESSAGE] FileLoadErrorGeneric: Microsoft.Extensions.Options
Internal.TypeSystem.TypeSystemException+FileNotFoundException: [TEMPORARY EXCEPTION MESSAGE] FileLoadErrorGeneric: Microsoft.Extensions.Options
   at Internal.TypeSystem.ThrowHelper.ThrowFileNotFoundException(ExceptionStringID id, String fileName)
   at ILCompiler.CompilerTypeSystemContext.GetModuleForSimpleName(String simpleName, Boolean throwIfNotFound)
   at Internal.TypeSystem.CustomAttributeTypeNameParser.GetTypeByCustomAttributeTypeName(ModuleDesc module, String name, Boolean throwIfNotFound, Func`4 resolver)
   at Internal.TypeSystem.CustomAttributeTypeNameParser.GetTypeByCustomAttributeTypeName(ModuleDesc module, String name, Boolean throwIfNotFound, Func`4 resolver)
   at ILCompiler.RdXmlRootProvider.ProcessTypeDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, XElement typeElement)
   at ILCompiler.RdXmlRootProvider.ProcessAssemblyDirective(IRootingServiceProvider rootProvider, XElement assemblyElement)
   at ILCompiler.RdXmlRootProvider.AddCompilationRoots(IRootingServiceProvider rootProvider)
   at ILCompiler.Compilation..ctor(DependencyAnalyzerBase`1 dependencyGraph, NodeFactory nodeFactory, IEnumerable`1 compilationRoots, DebugInformationProvider debugInformationProvider, Logger logger)
   at ILCompiler.ILScannerBuilder.ToILScanner()
   at ILCompiler.Program.Run(String[] args)
   at ILCompiler.Program.Main(String[] args)

I was able to resolve the issues by finding references for all the missing files, but in the end I realized I needed to switch the architecture target to x64, however now it fails at the linker:

C:\
cd \testapp
call link @".\link.rsp"

Output:

libcpmt.lib(nothrow.obj) : fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64'

Solution

  • The issue is caused by using the Developer Command Prompt instead of the x64 Native Tools Command Prompt. The former one targets x86 by default, but the latter one targets x64 and will link against the x64 libraries.