Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Deployment issue for hololens 2 ( error LNK2005: main already defined in *.obj)

Discussion in 'Editor & General Support' started by FridgeWalaby, Aug 9, 2022.

  1. FridgeWalaby

    FridgeWalaby

    Joined:
    Mar 6, 2016
    Posts:
    4
    I'm running into a build issue that keeps me from deploying to the hololens with VS2019.

    The project runs without error in Game Mode in the editor. Also the build step runs fine Build Settings>Build
    Then I open the generated .sln file in the generated build folder with VS2019. Next, I try to deploy it to the hololens 2 with options "Release" "ARM64" "Device".

    The deployment does not work and stops with the following errors:

    Build started...
    1>------ Build started: Project: Il2CppOutputProject, Configuration: Release ARM64 ------
    1>Building GameAssembly.dll with MsvcWinRtToolChain
    1> Msvc Install Version: 16.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\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\ARM64\link.exe
    1> Msvc Compiler Path: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\ARM64\cl.exe
    1>
    1> Output directory: C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\bin\ARM64\Release
    1> Cache directory: C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\obj\il2cppOutputProject\ARM64\Release
    1>ObjectFiles: 616 of which compiled: 0
    1>Total compilation time: 1071 milliseconds.
    1>EXEC : error : Unity.IL2CPP.Building.BuilderFailedException: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\ARM64\link.exe /out:"C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\obj\il2cppOutputProject\ARM64\Release\linkresult_4A449633D37B476CD67F1877C053ABDD\GameAssembly.dll" /ignore:4206 /DEBUG /INCREMENTAL:NO /LARGEADDRESSAWARE /NXCOMPAT /DYNAMICBASE /NOLOGO /TLBID:1 /OPT:REF /OPT:ICF /DLL /IGNORE:4104 /NODEFAULTLIB:uuid.lib "Shcore.lib" "WindowsApp.lib" "Crypt32.lib" "Iphlpapi.lib" "C:\Program Files\Unity\Hub\Editor\2021.3.5f1\Editor\Data\PlaybackEngines\MetroSupport\Players\UAP\il2cpp\ARM64\Release\baselib.dll.lib" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\ARM64\store" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\arm64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\arm64" /APPCONTAINER /SUBSYSTEM:WINDOWS /NODEFAULTLIB:eek:le32.lib /NODEFAULTLIB:kernel32.lib @"C:\Users\mwittwer\AppData\Local\Temp\tmpE5E.tmp"
    1>
    1>1B7536222DEA08C3E2118E21A2D25DED.obj : error LNK2005: main already defined in C61FD6AB731689A5856B3BA14514FC9B.obj
    1>C96DF2BA947785B7D6E7B007E44143A8.obj : error LNK2005: main already defined in C61FD6AB731689A5856B3BA14514FC9B.obj
    1> Creating library C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\obj\il2cppOutputProject\ARM64\Release\linkresult_4A449633D37B476CD67F1877C053ABDD\GameAssembly.lib and object C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\obj\il2cppOutputProject\ARM64\Release\linkresult_4A449633D37B476CD67F1877C053ABDD\GameAssembly.exp
    1>C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\obj\il2cppOutputProject\ARM64\Release\linkresult_4A449633D37B476CD67F1877C053ABDD\GameAssembly.dll : fatal error LNK1169: one or more multiply defined symbols found
    1>
    1> at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet`1 objectFiles, CppToolChainContext toolChainContext)
    1> at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
    1> at il2cpp.Compilation.CompilationDriver.Run(RuntimePlatform platform, Il2CppCommandLineArguments il2CppCommandLineArguments, BuildingOptions buildingOptions, ReadOnlyCollection`1 matchedAssemblyMethodSourceFiles)
    1> at il2cpp.Program.DoRun(String[] args, RuntimePlatform platform, Il2CppCommandLineArguments il2CppCommandLineArguments, BuildingOptions buildingOptions, Boolean throwExceptions)
    1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.MakeFile.Targets(46,5): error MSB3073: The command ""C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\Il2CppOutputProject\\IL2CPP\build\deploy\il2cpp.exe" --libil2cpp-static --compile-cpp -architecture=ARM64 -configuration=Release -platform=winrt -outputpath="C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\\build\bin\ARM64\Release\GameAssembly.dll" --data-folder="C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\\build\bin\ARM64\Release\\" -cachedirectory="C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\\build\obj\il2cppOutputProject\ARM64\Release\\" -generatedcppdir="C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\Il2CppOutputProject\\Source" --incremental-g-c-time-slice=3 --baselib-directory="C:\Program Files\Unity\Hub\Editor\2021.3.5f1\Editor\Data\PlaybackEngines\MetroSupport\Players\UAP\il2cpp\ARM64\Release" --avoid-dynamic-library-copy --dont-deploy-baselib --profiler-report --additional-defines=WINDOWS_UWP --additional-defines=UNITY_UWP --additional-defines=UNITY_WSA_10_0 --additional-defines=UNITY_WSA --additional-defines=UNITY_WINRT --additional-defines=PLATFORM_WINRT -dotnetprofile=unityaot-win32 -verbose --relative-data-path=Data/il2cpp_data" exited with code 4.
    1>Done building project "Il2CppOutputProject.vcxproj" -- FAILED.
    2>------ Build started: Project: master-thesis-mwittwer, Configuration: Release ARM64 ------
    2>App.cpp
    2>UnityGenerated.cpp
    2> Creating library C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\bin\ARM64\Release\master-thesis-mwittwer.lib and object C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\bin\ARM64\Release\master-thesis-mwittwer.exp
    2>Generating code
    2>Finished generating code
    2>master-thesis-mwittwer.vcxproj -> C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\bin\ARM64\Release\master-thesis-mwittwer.exe
    2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\v16.0\AppxPackage\Microsoft.AppXPackage.Targets(2991,5): error APPX0702: Payload file 'C:\Users\mwittwer\MyUnityProjects\master-thesis-mwittwer\build\build\bin\ARM64\Release\GameAssembly.dll' does not exist.
    2>Done building project "master-thesis-mwittwer.vcxproj" -- FAILED.
    ========== Build: 0 succeeded, 2 failed, 0 up-to-date, 0 skipped ==========
    ========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

    I see these two lines:
    1>1B7536222DEA08C3E2118E21A2D25DED.obj : error LNK2005: main already defined in C61FD6AB731689A5856B3BA14514FC9B.obj
    1>C96DF2BA947785B7D6E7B007E44143A8.obj : error LNK2005: main already defined in C61FD6AB731689A5856B3BA14514FC9B.obj

    These files are generated in one of the build steps. I'm a bit lost on how to resolve this issue?

    Thanks for any hints.

    I am using Unity 2021.3.5f1 on a Windows 10 PC.
     
  2. FridgeWalaby

    FridgeWalaby

    Joined:
    Mar 6, 2016
    Posts:
    4