title: Unity Android Build Works in Mono but Fails in IL2CPP due to Undefined References, Missing Library
body: <p>I'm attempting to update our ARToolkit5 based Unity Android app that has been in the Google Play store for years. ARToolkit5 is no longer supported, but we still rely on its libraries, built about 4 years ago. My Unity version is 2020.1.11f1.</p>
  <p>I need to upgrade the app to a Google App Bundle and add 64-bit support. So the first step, I understand, is to change from Mono to IL2CPP as the Scripting Backend. The 32-bit Android ARMv7 app builds in Mono and runs fine, but when I literally only make one change, which is flipping to IL2CPP as the Scripting Backend under Project Settings, the build fails. I haven't even tried adding the ARM64 option yet.</p>
  <p>When using IL2CPP the build fails with a <code>BuilderFailedException</code> and hundreds of <code>Undefined References</code>...</p>
  <pre><code>Exception: /Applications/2020.1.11f1/Unity.app/Contents/il2cpp/build/deploy/net471/il2cpp.exe did not run properly!
  
  Failed running &quot;/Applications/2020.1.11f1/Unity.app/Contents/il2cpp/build/deploy/net471/il2cpp.exe&quot; --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile=&quot;unityaot&quot; --compile-cpp --libil2cpp-static --platform=&quot;Android&quot; --architecture=&quot;ARMv7&quot; --configuration=&quot;Release&quot; --outputpath=&quot;&lt;redacted&gt;/Temp/StagingArea/assets/bin/Data/Native/armeabi-v7a/libil2cpp.so&quot; --cachedirectory=&quot;&lt;redacted&gt;/Assets/../Library/il2cpp_android_armeabi-v7a/il2cpp_cache&quot; --additional-include-directories=&quot;/Applications/2020.1.11f1/PlaybackEngines/AndroidPlayer/Tools/bdwgc/include&quot; --additional-include-directories=&quot;/Applications/2020.1.11f1/PlaybackEngines/AndroidPlayer/Tools/libil2cpp/include&quot; --baselib-directory=&quot;/Applications/2020.1.11f1/PlaybackEngines/AndroidPlayer/Variations/il2cpp/Release/StaticLibs/armeabi-v7a&quot; --avoid-dynamic-library-copy --tool-chain-path=&quot;/Applications/2020.1.11f1/PlaybackEngines/AndroidPlayer/NDK&quot; --profiler-report --map-file-parser=&quot;/Applications/2020.1.11f1/Unity.app/Contents/Tools/MapFileParser/MapFileParser&quot; --directory=&quot;&lt;redacted&gt;/Temp/StagingArea/assets/bin/Data/Managed&quot; --generatedcppdir=&quot;&lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput&quot;  
  
  stdout:
  Running il2cpp.exe in workstation GC mode.
  Building libil2cpp.so with AndroidToolChain
      Output directory: &lt;redacted&gt;/Temp/StagingArea/assets/bin/Data/Native/armeabi-v7a
      Cache directory: &lt;redacted&gt;/Library/il2cpp_android_armeabi-v7a/il2cpp_cache
  ObjectFiles: 186 of which compiled: 0
  Total compilation time: 157 milliseconds.
  il2cpp.exe didn't catch exception: Unity.IL2CPP.Building.BuilderFailedException: /Applications/2020.1.11f1/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ @&quot;/var/folders/vc/9b7436817vzgvxlqrftcl1nr0000gn/T/tmp1b926095.tmp&quot; -o &quot;&lt;redacted&gt;/Library/il2cpp_android_armeabi-v7a/il2cpp_cache/linkresult_01F24D8C43A06CD45FA9C75071D0A3D6/libil2cpp.so&quot; -shared -Wl,-soname,libil2cpp.so -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--gc-sections -Wl,--build-id -stdlib=libc++ -static-libstdc++ -target armv7-linux-androideabi19 -Wl,--wrap,sigaction &quot;/Applications/2020.1.11f1/PlaybackEngines/AndroidPlayer/Variations/il2cpp/Release/StaticLibs/armeabi-v7a/baselib.a&quot; -llog -rdynamic -fuse-ld=gold
  
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28131: error: undefined reference to 'arwRegisterLogCallback'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28140: error: undefined reference to 'arwSetLogLevel'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28149: error: undefined reference to 'arwInitialiseAR'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28159: error: undefined reference to 'arwInitialiseARWithOptions'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28173: error: undefined reference to 'arwGetARToolKitVersion'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28190: error: undefined reference to 'arwGetError'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28200: error: undefined reference to 'arwShutdownAR'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28221: error: undefined reference to 'arwStartRunningB'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28235: error: undefined reference to 'arwIsRunning'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28245: error: undefined reference to 'arwStopRunning'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28262: error: undefined reference to 'arwGetProjectionMatrix'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28276: error: undefined reference to 'arwGetVideoParams'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28293: error: undefined reference to 'arwCapture'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28303: error: undefined reference to 'arwUpdateAR'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28313: error: undefined reference to 'arwUpdateTexture32'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28323: error: undefined reference to 'arwGetMarkerPatternCount'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28340: error: undefined reference to 'arwGetMarkerPatternConfig'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28357: error: undefined reference to 'arwGetMarkerPatternImage'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28367: error: undefined reference to 'arwGetMarkerOptionBool'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28377: error: undefined reference to 'arwSetMarkerOptionBool'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28386: error: undefined reference to 'arwGetMarkerOptionInt'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28396: error: undefined reference to 'arwSetMarkerOptionInt'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28405: error: undefined reference to 'arwGetMarkerOptionFloat'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28415: error: undefined reference to 'arwSetMarkerOptionFloat'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28424: error: undefined reference to 'arwSetVideoDebugMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28433: error: undefined reference to 'arwGetVideoDebugMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28443: error: undefined reference to 'arwSetVideoThreshold'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28452: error: undefined reference to 'arwGetVideoThreshold'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28462: error: undefined reference to 'arwSetVideoThresholdMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28471: error: undefined reference to 'arwGetVideoThresholdMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28481: error: undefined reference to 'arwSetLabelingMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28490: error: undefined reference to 'arwGetLabelingMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28500: error: undefined reference to 'arwSetBorderSize'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28509: error: undefined reference to 'arwGetBorderSize'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28519: error: undefined reference to 'arwSetPatternDetectionMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28528: error: undefined reference to 'arwGetPatternDetectionMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28538: error: undefined reference to 'arwSetMatrixCodeType'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28547: error: undefined reference to 'arwGetMatrixCodeType'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28557: error: undefined reference to 'arwSetImageProcMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28566: error: undefined reference to 'arwGetImageProcMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28576: error: undefined reference to 'arwSetNFTMultiMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28585: error: undefined reference to 'arwGetNFTMultiMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28599: error: undefined reference to 'arwAddMarker'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28613: error: undefined reference to 'arwRemoveMarker'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28623: error: undefined reference to 'arwRemoveAllMarkers'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28633: error: undefined reference to 'arwQueryMarkerVisibility'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28650: error: undefined reference to 'arwQueryMarkerTransformation'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28685: error: undefined reference to 'arwLoadOpticalParams'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  
  
    at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles (System.Collections.Generic.HashSet`1[T] objectFiles, Unity.IL2CPP.Building.ToolChains.CppToolChainContext toolChainContext) [0x00203] in &lt;bb3d372ae2c942d1b47f060d5cd89a4d&gt;:0 
    at Unity.IL2CPP.Building.CppProgramBuilder.Build (Unity.IL2CPP.Building.Statistics.IBuildStatistics&amp; statistics) [0x0025c] in &lt;bb3d372ae2c942d1b47f060d5cd89a4d&gt;:0 
    at Unity.IL2CPP.Building.Statistics.BuildingTestRunnerHelper.BuildAndLogStatsForTestRunner (Unity.IL2CPP.Building.CppProgramBuilder builder, Unity.IL2CPP.Building.Statistics.IBuildStatistics&amp; statistics) [0x00000] in &lt;bb3d372ae2c942d1b47f060d5cd89a4d&gt;:0 
    at il2cpp.Compilation.CompilationDriver.Run (Unity.IL2CPP.Common.RuntimePlatform platform, Unity.IL2CPP.Building.BuildingOptions buildingOptions) [0x001fd] in &lt;3be9f628f5fa469389bd6a91a579ba8a&gt;:0 
    at il2cpp.Program.DoRun (System.String[] args, Unity.IL2CPP.Common.RuntimePlatform platform, Unity.IL2CPP.Building.BuildingOptions buildingOptions) [0x0001f] in &lt;3be9f628f5fa469389bd6a91a579ba8a&gt;:0 
    at il2cpp.Program.Run (System.String[] args, System.Boolean setInvariantCulture) [0x00063] in &lt;3be9f628f5fa469389bd6a91a579ba8a&gt;:0 
    at il2cpp.Program.Main (System.String[] args) [0x00000] in &lt;3be9f628f5fa469389bd6a91a579ba8a&gt;:0 
  stderr:
  
  Unhandled Exception:
  Unity.IL2CPP.Building.BuilderFailedException: /Applications/2020.1.11f1/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ @&quot;/var/folders/vc/9b7436817vzgvxlqrftcl1nr0000gn/T/tmp1b926095.tmp&quot; -o &quot;&lt;redacted&gt;/Library/il2cpp_android_armeabi-v7a/il2cpp_cache/linkresult_01F24D8C43A06CD45FA9C75071D0A3D6/libil2cpp.so&quot; -shared -Wl,-soname,libil2cpp.so -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--gc-sections -Wl,--build-id -stdlib=libc++ -static-libstdc++ -target armv7-linux-androideabi19 -Wl,--wrap,sigaction &quot;/Applications/2020.1.11f1/PlaybackEngines/AndroidPlayer/Variations/il2cpp/Release/StaticLibs/armeabi-v7a/baselib.a&quot; -llog -rdynamic -fuse-ld=gold
  
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28131: error: undefined reference to 'arwRegisterLogCallback'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28140: error: undefined reference to 'arwSetLogLevel'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28149: error: undefined reference to 'arwInitialiseAR'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28159: error: undefined reference to 'arwInitialiseARWithOptions'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28173: error: undefined reference to 'arwGetARToolKitVersion'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28190: error: undefined reference to 'arwGetError'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28200: error: undefined reference to 'arwShutdownAR'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28221: error: undefined reference to 'arwStartRunningB'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28235: error: undefined reference to 'arwIsRunning'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28245: error: undefined reference to 'arwStopRunning'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28262: error: undefined reference to 'arwGetProjectionMatrix'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28276: error: undefined reference to 'arwGetVideoParams'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28293: error: undefined reference to 'arwCapture'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28303: error: undefined reference to 'arwUpdateAR'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28313: error: undefined reference to 'arwUpdateTexture32'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28323: error: undefined reference to 'arwGetMarkerPatternCount'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28340: error: undefined reference to 'arwGetMarkerPatternConfig'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28357: error: undefined reference to 'arwGetMarkerPatternImage'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28367: error: undefined reference to 'arwGetMarkerOptionBool'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28377: error: undefined reference to 'arwSetMarkerOptionBool'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28386: error: undefined reference to 'arwGetMarkerOptionInt'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28396: error: undefined reference to 'arwSetMarkerOptionInt'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28405: error: undefined reference to 'arwGetMarkerOptionFloat'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28415: error: undefined reference to 'arwSetMarkerOptionFloat'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28424: error: undefined reference to 'arwSetVideoDebugMode'
  &lt;redacted&gt;/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28433: error: undefined referen&lt;message truncated&gt;
  </code></pre>
  <p>What I <em>think</em> this says is that the linker can't find definitions for the functions listed, all of which are from one ARToolkit library: <code>libARWrapper.so</code></p>
  <p>This library exists in the Unity project at: <code>Assets/Plugins/Android/lib/armeabi-v7a/libARWrapper.so</code>.</p>
  <p>A quick check in the Unity Inspector shows that the library Import Settings seem to be correct.</p>
  <p><a href="https://i.stack.imgur.com/oAs2C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oAs2C.png" alt="Unity Inspector: libARWrapper.so Import Settings" /></a></p>
  <p>This seems to indicate that this library will be included in Android ARMv7 builds, which this is. And I know the library works and runs on an ARMv7 device, and builds using Mono, so I think it is just somehow left out of the IL2CPP build.</p>
  <p>So in conclusion, Mono includes the libARWrapper.so library in its build, but when I flip over to IL2CPP for the exact same project, the library is not included and thus fails to link.
  Does anyone know why this would be? Thanks!</p>