---
title: 其他 IL2CPP 编译器 Arguments
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/zh-cn/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/il2cpp/handling-il2cpp-additional-args
latest_url: https://docs.unity.com/zh-cn/engine/7000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/il2cpp/handling-il2cpp-additional-args.md
generated_at: 2026-11-16T07:53:15.071Z
locale: zh-cn
---

# 其他 IL2CPP 编译器 Arguments

> 从代代码 IL2CPP 编译器提供自定义定义附加Arguments。

您可以使用 [`PlayerSettings.SetAdditionalIl2CppArgs`](/engine/6000.0/script-reference/unityeditor/playersettings/setadditionalil2cppargs.md) API 或通过设置 `IL2CPP_ADDITIONAL_ARGS` Environment 变量为 IL2CPP 编译器提供其他 Arguments。

> **Warning:**
>
> 将其他Arguments传递给 IL2CPP 编译器是在复杂Projects中调试和优化 IL2CPP 代码生成的实验性的性功能。与\[诊断交换机]一样(/engine/6000.0/manual/unity-editor/editor-settings-reference/preferences/editor-diagnostics)，它供高级开发人员与 Unity Support 人员协调使用。Arguments 在没有解释的情况下直接传递给 C++ 编译器，这意味着破坏构建的高风险。Unity 保留Change或移除此功能的权利，恕不另行通知。

表显示了使用于向 IL2CPP 编译器提供其他标志的Arguments：

| **参数**                       | **描述**                                                                                                                                               |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--compiler-flags="<flags>"` | 将其他标志传递给 C++ 编译器。将 `<flags>` 替换为所需的标志。例如，`--compiler-flags=\"COMPILER_FLAG_1 COMPILER_FLAG_2\"`将编译器标志`COMPILER_FLAG_1`和`COMPILER_FLAG_2`传递给 C++ 编译器。 |
| `--linker-flags="<flags>"`   | 将其他标志传递给链接器。将 `<flags>` 替换为所需的标志。例如，`--linker-flags="\LINKER_FLAG_1 LINKER_FLAG_2\"` 将链接器标志 `LINKER_FLAG_1` 和 `LINKER_FLAG_2` 传递给链接器。                |

多个个Arguments必须以Space分隔，如下所示：

```lang-cs
PlayerSettings.SetAdditionalIl2CppArgs("--compiler-flags=\"COMPILER_FLAG_1 COMPILER_FLAG_2\" --linker-flags="\LINKER_FLAG_1 LINKER_FLAG_2\"");
```

> **Note:**
>
> 多次调用 `SetAdditionalIl2CppArgs` 会覆盖以前提供的任何标志。将空字符串通道给此方法可移除以前提供的Any附加Arguments。

有效的编译器器和链接器标志因平台而异，具体取决ON IL2CPP ON该平台上使用的底层 C++ 编译器（msvc 或 clang）。有关有效编译器和链接器选项的列表，请参阅 msvc [编译器](https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-170)、[链接器](https://learn.microsoft.com/en-us/cpp/build/reference/linker-options?view=msvc-170)选项或 [clang 编译器和链接](https://clang.llvm.org/docs/ClangCommandLineReference.html)器选项的相关第三方文档。

## Check是否设置了Arguments##check-if-arguments-are-set

如果 Project 设置了其他 IL2CPP Arguments，那么针对多个平台的编译可能无法按预期工作，尤其是当[针对 Linux 交叉编译](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/il2cpp/linux-il2cpp-crosscompiler.md)时。

要检查是否已设置Any其他 IL2CPP Arguments，请执行以下操作之一：

* Check if the Environment variable `IL2CPP_ADDITIONAL_ARGS` is seted.
* `ProjectSettings/ProjectSettings.asset`，检查 Editor 脚本是否具有名为 `additionalIl2CppArgs` 的值。

> **Important:**
>
> 其他 IL2CPP Arguments 全局应用于 All 平台，如果设置为所需平台以外的其他平台，可能会导致编译问题。使用 `IPreprocessBuildWithContext` 钩子可确保仅为需要 IL2CPP Arguments 的平台设置这些参数。

### IPreprocessBuildWithContext 钩子##ipreprocessbuildwithcontext-hook

您可以使用 [`IPreprocessBuildWithContext`](ScriptRef:Build.IPreprocessBuildWithContext) 回调来生成脚本，或使用 生成对话框来设置其他 Arguments：

```lang-cs
类 MyCustomPreprocessBuild：IPreprocessBuildWithReport
{
    public int callbackOrder { get { return 0; } }
    public void OnPreprocessBuild(BuildReport report)
    {
        string addlArgs = "";
        if (report.summary.platform == BuildTarget.StandaloneWindows || 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);
    }
}
```

## 其他资源##additional-resources

* [Linux IL2CPP cross-compiler](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/il2cpp/linux-il2cpp-crosscompiler.md)
* [托管堆栈跟踪](/engine/6000.0/manual/scripting/compilation-and-code-reload/script-compilation/backends/il2cpp/il2cpp-managed-stack-traces.md)
* Discussions如何为 IL2CPP 调用]\([https://discussions.unity.com/t/how-to-add-compiler-or-linker-flags-for-il2cpp-invocation/221183)添加编译器或链接器标志](https://discussions.unity.com/t/how-to-add-compiler-or-linker-flags-for-il2cpp-invocation/221183\)添加编译器或链接器标志)
