error: use of undeclared identifier 'il2cpp_codegen_initialize_method

I have a unity project that I’m using as a library for unity. I upgraded my old project to unity 2020.3 and I’m having a building error like this.

D:\project\unityLibrary\src\main\Il2CppOutputProject\Source\il2cppOutput\Il2CppAttributes.cpp:8870:3: error: use of undeclared identifier 'il2cpp_codegen_initialize_method'
                il2cpp_codegen_initialize_method (PropertyInfo_t_CustomAttributesCacheGenerator_MetadataUsageId);
                ^
D:\project\unityLibrary\src\main\Il2CppOutputProject\Source\il2cppOutput\Il2CppAttributes.cpp:10033:3: error: use of undeclared identifier 'il2cpp_codegen_initialize_method'
                il2cpp_codegen_initialize_method (SemaphoreSlim_t3EF85FC980AE57957BEBB6B78E81DE2E3233D385_CustomAttributesCacheGenerator_SemaphoreSlim_WaitUntilCountOrTimeoutAsync_mDC94D9B33D339D5EB3B148DD1A20AB756D2605A2_MetadataUsageId);
                ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.


Invocation was: Executable: "C:\Users\acer\AppData\Local\Android\Sdk\ndk\20.0.5594570\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++"
Arguments: -DNET_4_0 -DUNITY_AOT -DIL2CPP_MONO_DEBUGGER_DISABLED -DGC_NOT_DLL -DRUNTIME_IL2CPP -DBASELIB_INLINE_NAMESPACE=il2cpp_baselib -DLINUX -DANDROID -DPLATFORM_ANDROID -D__linux__ -D__STDC_FORMAT_MACROS -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\external\bdwgc\include" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\libil2cpp\include" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\libil2cpp" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\libil2cpp" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\external\bdwgc\include" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\external\xxHash" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\external\baselib\Include" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\external\baselib\Platforms\Android\Include" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\IL2CPP\libil2cpp\pch" -I"D:\project\unityLibrary\src\main\Il2CppOutputProject\Source\il2cppOutput" -I"." -c -g -DNDEBUG -fexceptions -fno-limit-debug-info -fdata-sections -ffunction-sections -Wa,--noexecstack -fno-rtti -std=c++11 -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -fno-strict-overflow -fno-addrsig -fPIC -Os -stdlib=libc++ -target armv7-linux-androideabi19 -D__ANDROID_API__=19 -march=armv7-a -mfloat-abi=softfp -mfpu=neon-fp16 -Wno-unused-value "D:\project\unityLibrary\src\main\Il2CppOutputProject\Source\il2cppOutput\Il2CppAttributes.cpp" -o ""D:\project/unityLibrary/build/il2cpp_armeabi-v7a_Release/il2cpp_cache/5FA346F9DCFBD3A2F492408D19AEDB1C.o"

   at Unity.IL2CPP.Building.CppProgramBuilder.BuildAllCppFiles(IEnumerable`1 sourceFilesToCompile, IBuildStatisticsCollector statisticsCollector)
   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
   at il2cpp.Compilation.CompilationDriver.Run(RuntimePlatform platform, BuildingOptions buildingOptions)
   at il2cpp.Program.DoRun(String[] args, RuntimePlatform platform, BuildingOptions buildingOptions)
   at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
   at il2cpp.Program.Main(String[] args)

> Task :unityLibrary:BuildIl2CppTask FAILED

Execution failed for task ':unityLibrary:BuildIl2CppTask'.
> Process 'command '"D:\project/unityLibrary/src/main/Il2CppOutputProject/IL2CPP/build/deploy/net471/il2cpp.exe'' finished with non-zero exit value -532462766

Can anyone help me or guide me through how to solve this?

It looks like a header file cannot be found. I’m not sure what it is happening differently here since Unity is built as a library though. Can you use the same installation to build a empty project with Unity? That should validate that the proper header exists in the Unity installation.

Thank you for your reply. Yes, I will follow up and check.

hi, @JoshPeterson I’ve checked it with an empty project. But there is no Il2cppAttribute.CPP file on unityLibrary\src\main\Il2CppOutputProject\Source\il2cppOutput folder. Seems like it is not created during the exportation.

Ahh ok, I think I see what happened here. In 2020.3, IL2CPP no longer generates a Il2CppAttributes.cpp file. In addition, the il2cpp_codegen_initialize_method function no longer exists. Both existed in 2019.4 and earlier.

So it look like there is some stale generated source code here, left over from a previous Unity version. If it is possible to remove that stale code, then this might work.

@JoshPeterson Thank you. Let me clear one thing, if there is no Il2CppAttributes.cpp file generate anymore on these versions, how is that possible to call such a method from other classes? Also, I will try your suggestion as well.

Which method specifically do you mean?

il2cpp_codegen_initialize_method.
I may be mistaken because I’m kinda new to this Android-related stuff.

That method no longer exists in Unity 2020.3. However, you should never write code which calls that method. It is an implementation detail of the way that IL2CPP generates C++ code. As long as all of the code generated for a project is generated with the same version of Unity, this error should not occur.

Oh, I see. I hope that this stuff is not related to native calls between unity and ios/ android. Anyhow, I’m on process of cleaning the project. I will keep you posted

No, this should not be related to native calls at all.