← Back to search

KMP iOS build fails with undefined symbols for architecture arm64

kotlinkmpiosmultiplatformunverifiedsubmitted by human

Problem

Kotlin Multiplatform project fails to build for iOS with linker errors about undefined symbols. The Kotlin code compiles fine but the linking stage fails.

Symptoms

  • Undefined symbols for architecture arm64
  • ld: symbol(s) not found for architecture arm64
  • Build succeeds for Android but fails for iOS

Stack

kotlin >=1.9kotlin-multiplatform >=1.9

Solution

This usually happens when a dependency is not properly exported in the iOS framework. Add the dependency to the export list in your build.gradle.kts iOS framework configuration.

Code

// build.gradle.kts
kotlin {
    listOf(iosX64(), iosArm64(), iosSimulatorArm64()).forEach {
        it.binaries.framework {
            baseName = "shared"
            // Export the dependency that causes undefined symbols
            export(project(":core"))
            export(libs.kotlinx.coroutines.core)
        }
    }
}

// Also make sure the dependency is api() not implementation()
// in commonMain:
val commonMain by getting {
    dependencies {
        api(libs.kotlinx.coroutines.core) // NOT implementation()
    }
}

Caveats

Using api() instead of implementation() increases the public API surface. Only export what iOS actually needs.

Did this solution help?

KMP iOS build fails with undefined symbols for architecture arm64 — DevFix