Additional IL2CPP compiler arguments
Supply custom additional arguments to the IL2CPP compiler from code.
Read time 3 minutesLast updated 11 days ago
You can provide additional arguments for the IL2CPP compiler using the API or by setting the environment variable.
PlayerSettings.SetAdditionalIl2CppArgsIL2CPP_ADDITIONAL_ARGSThe following table displays the arguments you can use to provide additional flags to the IL2CPP compiler:
Argument | Description |
|---|---|
| Passes additional flags to the C++ compiler. Replace |
| Passes additional flags to the linker. Replace |
Multiple arguments must be space separated as follows:
PlayerSettings.SetAdditionalIl2CppArgs("--compiler-flags=\"COMPILER_FLAG_1 COMPILER_FLAG_2\" --linker-flags="\LINKER_FLAG_1 LINKER_FLAG_2\"");
Valid compiler and linker flags differ by platform, depending on which underlying C++ compiler (msvc or clang) IL2CPP uses on that platform. For a list of valid compiler and linker options, refer to the relevant third-party documentation for msvc compiler, linker options, or clang compiler and linker options.
Check if arguments are set
If your project has additional IL2CPP arguments set, then compiling for more than one platform might not work as expected, especially when cross-compiling for Linux.
To check if any additional IL2CPP arguments are already set, do one of the following:
- Check if the environment variable is set.
IL2CPP_ADDITIONAL_ARGS - In , check if the Editor script has a value called
ProjectSettings/ProjectSettings.asset.additionalIl2CppArgs
IPreprocessBuildWithContext hook
You can use the callback to build scripts or the Build dialog to set the additional arguments:
IPreprocessBuildWithContextclass MyCustomPreprocessBuild: IPreprocessBuildWithContext{ public int callbackOrder { get { return 0; } } public void OnPreprocessBuild(BuildCallbackContext ctx) { string addlArgs = ""; if (ctx.Report.summary.platform == BuildTarget.StandaloneWindows || ctx.Report.summary.platform == BuildTarget.StandaloneWindows64) addlArgs = "--compiler-flags=\"d2ssa-cfg-jt\""; UnityEngine.Debug.Log($"Setting Additional IL2CPP Args = \"{addlArgs}\" for platform {report.summary.platform}"); PlayerSettings.SetAdditionalIl2CppArgs(addlArgs); }}