全部配置 / KN-NOSTDLIB

nostdlib

nostdlib · KN-NOSTDLIB · 编译器参数(Native)

重要:中 · 场景相关 默认:默认关 场合:场景可配 来源:上游原样

默认值:默认关。false(BooleanType.defaultFalse)。使用场合:场景可配。场景可配:有明确目标(性能、包体、安全、兼容)时再改。

它是做什么的

用途。不自动链接标准库。原文:Don't link with the stdlib.

影响。影响链接输入/库搜索;配错常见表现是缺符号或链接失败。

适用场景。场景可配。有明确需求再改,无需求时保持发行版默认更稳妥。改前核对目标限制与联动项,改后做冒烟。

取值说明

布尔 · 写法 -nostdlib(开启) · 默认 false(BooleanType.defaultFalse)

可写。(开关存在 / true) / false / 不传

定义依据:description/NativeCompilerArguments.kt 在仓库中打开

怎么用

  1. 配置入口:build.gradle.kts → ohosArm64.binaries.all { freeCompilerArgs += "-nostdlib" }
  2. 示例
// 文件:build.gradle.kts(应用的 Kotlin 模块,例如 composeApp)
kotlin {
  ohosArm64 {  // 按实际 native target 调整
    binaries.all {
      freeCompilerArgs += "-nostdlib"
    }
  }
}
  1. 生效:Sync 后执行该目标的 compile/link。
  2. 验证:编译日志出现 `-nostdlib`。
  3. 回滚:从 binaries.all 的 freeCompilerArgs 中删除该项后 Clean 并重编。
  4. 注意:按 Debug/Release 分流配置,避免公共污染。

默认行为 默认关

不写这个配置时,编译器会怎么处理?

此选项默认关闭,不设置时不生效。需要时显式开启。

false(BooleanType.defaultFalse)。

相关文档

以下摘抄原文中与本配置最相关的段落,便于速读;完整上下文请点原文。

上游 · Kotlin compiler options · Native

-nopack

Don't pack the library into a klib file.

-nostdlib

Don't link with stdlib.

-opt

Enable compilation optimizations and produce a binary with better runtime performance. It's not recommended to combine it with the -g option, which lowers the optimization level.

-output name (-o name )

Set the name for the output file.

-produce output (-p output )

Specify output file kind:

program

打开原文

溯源与对照

状态
稳定(正式选项)
版本基线
2.2.21-1.0.0
定义位置类型
编译器参数定义(arguments DSL)
源码路径
compiler/arguments/src/org/jetbrains/kotlin/arguments/description/NativeCompilerArguments.kt 在仓库中打开