Failed running il2cpp.exe on build for Windows

I tried building my project for windows, and get the following errors:

Failed running C:\Program Files\Unity\Hub\Editor\2019.4.9f1\Editor\Data\il2cpp/build/deploy/net471/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile="unityaot" --compile-cpp --libil2cpp-static --platform="WindowsDesktop" --architecture="x64" --configuration="Release" --outputpath="E:\Github\Rebot\Temp/StagingArea/Data\Native\GameAssembly.dll" --cachedirectory="E:\Github\Rebot\Assets\..\Library/il2cpp_cache" --profiler-report --map-file-parser="C:/Program Files/Unity/Hub/Editor/2019.4.9f1/Editor/Data/Tools/MapFileParser/MapFileParser.exe" --directory=E:/Github/Rebot/Temp/StagingArea/Data/Managed --generatedcppdir=E:/Github/Rebot/Temp/StagingArea/Data/il2cppOutput

stdout:
il2cpp.exe didn't catch exception: System.InvalidOperationException: C++ code builder is unable to build C++ code. In order to build C++ code for Windows Desktop, you must have one of these installed:
        Visual Studio 2015 with C++ compilers and Windows 10 SDK (it cannot build C++ code because it is not installed)
        Visual Studio 2015 installation is found by looking at "SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstallDir" in the registry
        Windows 10 SDK is found by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry

        Visual Studio 2017 with C++ compilers and Windows 10 SDK (it cannot build C++ code because it is not installed)
        Visual Studio 2017 installation is found using Microsoft.VisualStudio.Setup.Configuration COM APIs
        Windows 10 SDK is found by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry


   at Unity.IL2CPP.Building.CppProgramBuilder.ThrowIfCannotBuildInCurrentEnvironment()
   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
   at il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
   at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
   at il2cpp.Program.Main(String[] args)
stderr:

Unhandled Exception: System.InvalidOperationException: C++ code builder is unable to build C++ code. In order to build C++ code for Windows Desktop, you must have one of these installed:
        Visual Studio 2015 with C++ compilers and Windows 10 SDK (it cannot build C++ code because it is not installed)
        Visual Studio 2015 installation is found by looking at "SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstallDir" in the registry
        Windows 10 SDK is found by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry

        Visual Studio 2017 with C++ compilers and Windows 10 SDK (it cannot build C++ code because it is not installed)
        Visual Studio 2017 installation is found using Microsoft.VisualStudio.Setup.Configuration COM APIs
        Windows 10 SDK is found by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry


   at Unity.IL2CPP.Building.CppProgramBuilder.ThrowIfCannotBuildInCurrentEnvironment()
   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
   at il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
   at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
   at il2cpp.Program.Main(String[] args)

UnityEngine.Debug:LogError(Object)
UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase)
UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1)
UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String)
UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(Il2CppBuildPipelineData, String, String, Boolean)
UnityEditorInternal.IL2CPPBuilder:Run()
UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry)
DesktopStandalonePostProcessor:SetupStagingArea(BuildPostProcessArgs, HashSet`1)
DesktopStandalonePostProcessor:PostProcess(BuildPostProcessArgs)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Then

Exception: C:\Program Files\Unity\Hub\Editor\2019.4.9f1\Editor\Data\il2cpp/build/deploy/net471/il2cpp.exe did not run properly!
UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List`1[T] arguments, System.Action`1[T] setupStartInfo, System.String workingDirectory) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (UnityEditor.Il2Cpp.Il2CppBuildPipelineData data, System.String outputDirectory, System.String workingDirectory, System.Boolean platformSupportsManagedDebugging) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
UnityEditorInternal.IL2CPPBuilder.Run () (at <d3ff43e972b043d1b3f49905ec5da738>:0)
UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
DesktopStandalonePostProcessor.SetupStagingArea (UnityEditor.Modules.BuildPostProcessArgs args, System.Collections.Generic.HashSet`1[T] filesToNotOverwrite) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
DesktopStandalonePostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
DesktopStandalonePostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <d3ff43e972b043d1b3f49905ec5da738>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Finally

UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
  at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002bb] in <d3ff43e972b043d1b3f49905ec5da738>:0
  at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <d3ff43e972b043d1b3f49905ec5da738>:0
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

I tried creating a new project in same editor 2019.4.9f1 (LTS), and building that one was successful without any problems. Also tried deleting Library and removing 3rd party assets.

Any ideas??

Did you try installing VIsual Studio? Any version that’s 2015 or newer (meaning 2015, 2017 and 2019) should work. From the error message:

C++ code builder is unable to build C++ code. In order to build C++ code for Windows Desktop, you must have one of these installed:
       Visual Studio 2015 with C++ compilers and Windows 10 SDK (it cannot build C++ code because it is not installed)
       Visual Studio 2015 installation is found by looking at "SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstallDir" in the registry
       Windows 10 SDK is found by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry
       Visual Studio 2017 with C++ compilers and Windows 10 SDK (it cannot build C++ code because it is not installed)
       Visual Studio 2017 installation is found using Microsoft.VisualStudio.Setup.Configuration COM APIs
       Windows 10 SDK is found by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry

@Tautvydas-Zilys but i just built a new project from same editor.

I also saw what that error message said, but i dont think thats the reason. I have always used Rider, but guess i could try to install it to see.

I guess i could try to create a completely new project, and transfer my scripts etc in parts. While trying to build every time, to see what (if anything) in my project makes it so i cant build.

Your project is setup to use IL2CPP scripting backend in player settings. To build with IL2CPP on Windows Standalone, you need a C++ compiler, which comes from Visual Studio and Windows 10 SDK. Creating a new project will not make this requirement go away.

Note that this requirement is unrelated to what you use to edit scripts. You may continue to use Rider as your C# code editor.

Thanks @Tautvydas-Zilys !
Installing VS2019 (MSVC 142) fixed it for me.

I have earlier installed MSVC 141 (2017) but for some reason it seems to not be able to pick it up.

I see a lot of threads on this in Unity forums, perhaps you should add a note to your IL2CPP docs that IL2CPP requires Windows 10 SDK and MSVC 14x. Unity - Manual: IL2CPP Overview

I remember I used to be able to only install Build tools, but it seems like Microsoft forces you to install Visual Studio 2019 now in order to get the latest MSVC…

Hmm, VS 2017 should have worked too. Perhaps it was missing some C++ components? But I agree, we should improve the error messages here.

Yeah, could be - i prefer to not install VS2017 when i use Rider anyway. So i never installed vs. Ms had standalone build tools you could download before to get only the needed tools to build i think.

I was having issues with this and didn’t understand why it wasn’t working because I had a VS 2019 installed.
Reading through the error messages it says it requires either VS 2017 or 2015.
I begrudgingly installed VS 2017 and even had to join some Microsoft dev ops program to get the install (lol) … but voila it now works.

Raises a question why VS 2019 is the only option in the Unity Bridge add-modules menu.
I did notice though that even if I had VS 2019 installed it was still an option to install over and over again. With VS 2017 and VS 2019 installed that option disappeared.

Using Unity 2019.4.9f1 LTS and also tried on 2019.4.10f1 LTS.

Actually VS2019 should work, but you need C++ components installed in it. We need to update the error message…

After going through this all over on a new computer the C++ components in question is the Game development with C++ workload which isn’t selected by default.

It’s not enough just to have Game development with Unity.

1 Like