Search Unity

Question Linker error LNK1112 building for HoloLens 2 using IL2CPP

Discussion in 'VR' started by smenyhart, Aug 18, 2020.

  1. smenyhart

    smenyhart

    Joined:
    May 6, 2016
    Posts:
    45
    I'm having a build issue while trying to build for HoloLens 2 on the ARM platform using Unity version 2018.4.23, but only if I build with IL2CPP. The same exact project, with no other changes other than switching the scripting backend from IL2CPP to .NET builds, deploys and runs on the HoloLens 2 perfectly fine. But when using the IL2CPP backend, I get the following linker error:

    fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'ARM'

    I get this same error when trying to build another project for HoloLens 2 using Unity version 2019.4, which only supports IL2CPP builds.

    So far I've tried building with both Visual Studio 2017 and 2019, and I have installed every package having to do with ARM and ARM64 platforms, but nothing has helped.

    I've also made sure to completely delete the build directories to make sure there were no old build remnants from x86 builds. Also I've checked all my library and include paths in the project settings and they all seem to point to the ARM versions.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Is the command line provided to the linker available in the editor log? That might provide a clue about the cause.
     
  3. smenyhart

    smenyhart

    Joined:
    May 6, 2016
    Posts:
    45
    I'm not sure I understand the question. Do you mean the Unity Editor Log? The IL2CPP build is done from a Visual Studio project generated by building in Unity Editor, and building that Visual Studio project is when the linker error happens. The only thing in the Unity Editor Log is a line about the build having succeeded, when it built the Visual Studio project.

    I can however get the linker command line out of the Visual Studio project properties. Here they are:

    /OUT:"D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\bin\ARM\Release\HoloCollaboration.exe" /MANIFEST:NO /LTCG /NXCOMPAT /PDB:"D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\bin\ARM\Release\HoloCollaboration.pdb" /DYNAMICBASE "WindowsApp.lib" "D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\bin\ARM\Release\GameAssembly.lib" /DEBUG:FULL /MACHINE:ARM /WINMD /APPCONTAINER /OPT:REF /PGD:"D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\bin\ARM\Release\HoloCollaboration.pgd" /WINMDFILE:"D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\bin\ARM\Release\HoloCollaboration.winmd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:NO /ManifestFile:"D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\obj\HoloCollaboration\ARM\Release\HoloCollaboration.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:pROMPT /NOLOGO /TLBID:1
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, this is the command line I wanted to see. Sorry, I did not realize the Hololnes builds in Visual Studio, and not from the Unity editor directly.

    I suspect that there must be some library or object file here that is compiled for x86 instead of ARM, although nothing jumps out at me.
     
  5. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    Yeah this sounds like some wonkiness with Visual Studio.

    First though, sorry for the dumb question but gotta ask: does your Unity project import any native plugins? Typically this error indicates an x86 native library is being included in your ARM build, but since this error only occurs with IL2CPP that's probably not the case.

    I did some googling and found these links that address this type of error:
    https://github.com/microsoft/Windows-iotcore-samples/issues/366
    https://stackoverflow.com/questions...ne-type-x64-conflicts-with-target-machine-typ

    Also, try using the /VERBOSE option for the Linker to get more detailed build output:
    https://docs.microsoft.com/en-us/cpp/build/reference/verbose-print-progress-messages?view=vs-2019

    Basically, it sounds like the Visual Studio project is somehow misconfigured, which could either because of problem with VS installation or Unity generated an improper project file. However, the actual cause could be any number of things: wrong build target, wrong build tools, wrong path, etc. The /VERBOSE should help identify exactly what's causing link.exe to choke.

    If you determine that Unity is generating an incorrect VS Project file, then please file a bug for this.
     
  6. smenyhart

    smenyhart

    Joined:
    May 6, 2016
    Posts:
    45
    Unfortunately turning on the /VERBOSE setting didn't really produce any new output.

    1>ObjectFiles: 913 of which compiled: 913
    1> Time Compile: 29219 milliseconds Il2CppTypeDefinitions.cpp
    1> Time Compile: 16517 milliseconds Il2CppComCallableWrappers58.cpp
    1> Time Compile: 16469 milliseconds Bulk_mscorlib_7.cpp
    1> Time Compile: 15378 milliseconds Il2CppComCallableWrappers44.cpp
    1> Time Compile: 15344 milliseconds Il2CppAttributes.cpp
    1> Time Compile: 14016 milliseconds Il2CppComCallableWrappers53.cpp
    1> Time Compile: 13857 milliseconds Bulk_ZXing_4.cpp
    1> Time Compile: 13756 milliseconds Il2CppComCallableWrappers40.cpp
    1> Time Compile: 13737 milliseconds Il2CppComCallableWrappers56.cpp
    1> Time Compile: 13502 milliseconds Il2CppComCallableWrappers31.cpp
    1>Total compilation time: 250824 milliseconds.
    1>Creating library D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\obj\il2cppOutputProject\ARM\Release\linkresult_743EE58BD813FCFB9FD8F400A4F441AD\GameAssembly.lib and object D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\obj\il2cppOutputProject\ARM\Release\linkresult_743EE58BD813FCFB9FD8F400A4F441AD\GameAssembly.exp
    1>Total link time: 34680 milliseconds.
    1>Cleaned up 1 object files.
    2>------ Rebuild All started: Project: HoloCollaboration, Configuration: Release ARM ------
    2>pch.cpp
    2>App.cpp
    2>Main.cpp
    2>UnityGenerated.cpp
    2>d:\workdir\gitrepos\sp246-arf-hololens2\src-unity\holocollaborationunity\build.il2cpp\holocollaboration\app.cpp(26): warning C4973: 'Windows::UI::ViewManagement::IApplicationView2::SuppressSystemOverlays::set': marked as deprecated
    2>d:\workdir\gitrepos\sp246-arf-hololens2\src-unity\holocollaborationunity\build.il2cpp\holocollaboration\app.cpp(26): note: Message: 'Use the TryEnterFullScreen method and IsFullScreenMode property instead of SuppressSystemOverlays. For more info, see MSDN.'
    2>
    2>Starting pass 1
    2>D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\obj\HoloCollaboration\ARM\Release\App.obj : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'ARM'
    2>Done building project "HoloCollaboration.vcxproj" -- FAILED.
    ========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

    The Unity project does not use any native code plugins, but it does use UWP compiled plugin DLLs. These all have ARM versions, which is why the .NET backend version compiles and runs correctly.

    I too suspected that a native code plugin might cause this sort of issue, but then I would expect the .NET backend version to fail in the same way.

    It could very well be that I have a mis-configured version of Visual Studio for both 2017 and 2019, I just have no idea how to fix it. I guess I could try a complete reinstall of them but that's pretty much an all day en-devour.
     
  7. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    If you don't mind, could you please attach the VS Project files for both the "app" (i.e. HoloCollaboration.vcxproj) and the Il2CppOutputProject.vcxproj?

    We should be able to determine if the project files themselves are misconfigured or if there something else
    Thanks.
     
  8. smenyhart

    smenyhart

    Joined:
    May 6, 2016
    Posts:
    45
    Yep here you go.
     

    Attached Files:

  9. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    The project files do appear to be correct and so the issue seems to be a VS configuration problem.

    Based on the error message:
    ...\build\obj\HoloCollaboration\ARM\Release\App.obj : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'ARM'

    App.cpp was apparently compiled to x86 but placed in the ARM output folder. This probably means the wrong C++ compiler is being used or the wrong output folder is being used. BTW, does building for x86 work?

    All that to say, the problem seems like mismatched compiler/linker path, and I need to see which paths VS is actually using. This should be outputted at the very start of the build and looks something like this:

    Building GameAssembly.dll with MsvcWinRtToolChain
    1> Msvc Install Version: 15.0
    1> Msvc Install SDK Directory: C:\Program Files (x86)\Windows Kits\10
    1> Msvc Linker Path: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\bin\HostX64\ARM\link.exe
    1> Msvc Compiler Path: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.26.28801\bin\HostX64\ARM\cl.exe
    1> Output directory: C:\Users\timke\Documents\Unity\<project>\build\bin\ARM\Debug
    1> Cache directory: C:\Users\timke\Documents\Unity\<project>\build\obj\il2cppOutputProject\ARM\Debug
     
  10. smenyhart

    smenyhart

    Joined:
    May 6, 2016
    Posts:
    45
    Yes the x86 build succeeds.

    Here's the output you asked for:
    Code (csharp):
    1.  
    2. 1>------ Rebuild All started: Project: Il2CppOutputProject, Configuration: Release ARM ------
    3. 1>Building GameAssembly.dll with MsvcWinRtToolChain
    4. 1>    Msvc Install Version: 15.0
    5. 1>    Msvc Install SDK Directory: C:\Program Files (x86)\Windows Kits\10
    6. 1>    Msvc Linker Path: c:\apps\MVS16\VC\Tools\MSVC\14.20.27508\bin\HostX64\ARM\link.exe
    7. 1>    Msvc Compiler Path: c:\apps\MVS16\VC\Tools\MSVC\14.20.27508\bin\HostX64\ARM\cl.exe
    8. 1>
    9. 1>    Output directory: D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\bin\ARM\Release
    10. 1>    Cache directory: D:\workdir\gitrepos\sp246-arf-HoloLens2\src-unity\HoloCollaborationUnity\Build.IL2CPP\build\obj\il2cppOutputProject\ARM\Release
    11.  
     
  11. smenyhart

    smenyhart

    Joined:
    May 6, 2016
    Posts:
    45
    Ok so after spending all day repairing both my Visual Studio 2017 and 2019 installations, the build now works without that linker error. And the built app also deploys and runs fine on the HoloLens 2 just like the .NET version does.

    Thank you for the help trying to debug this. I wish I could tell you more about how my VS installations could of become messed up like this, but I'm afraid I have no idea.
     
  12. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    I'm glad you got it working and sorry you had such an ordeal with VS.

    I've lost count of the number of times I wanted to put my fist through the monitor screen because of Visual Studio. But this...goes far past the typical BS. My only guess is installing to a custom folder (i.e. not Program Files (x86)) caused something to go horribly wrong.

    Anyway, hope you have a better time going forward.