hi all, i am using issue integrating sqldelight with KMM with ``app.cash.sqldelight:sqlite-3-38-dial...
b
hi all, i am using issue integrating sqldelight with KMM with ``app.cash.sqldelightsqlite 3 38 dialect2.0.0-alpha02``, it is working for android, but not for the ios
i am having the following error
Copy code
LinkDylibError: Failed to build ContentView.swift

Linking failed: linker command failed with exit code 1 (use -v to see invocation)

ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator'
Undefined symbols for architecture x86_64:
  "_sqlite3_aggregate_context", referenced from:
      _co_touchlab_sqliter_sqlite3_sqlite3_aggregate_context_wrapper139 in shared(result.o)
k
Is this a new project or are you upgrading from an earlier version? If not upgrading, then I don’t know that this would be specific to
3-38
. The error means you don’t have sqlite linked to the build. It looks like no version of iOS ships with 3.38 (https://github.com/yapstudios/YapDatabase/wiki/SQLite-version-(bundled-with-OS)). I haven’t tried different dialects myself, so not sure there’s anything to dig into there. You could build your own sqlite, but I don’t think you’d be getting that linker error if you did.
Again, I haven’t tried other dialects, but if it’s just a linking issue, see here: https://github.com/cashapp/sqldelight/issues/1442#issuecomment-1048131450
b
it’s a new project, here is what i have
Copy code
plugins{ id("app.cash.sqldelight") }

sqldelight {
    database("AppDatabase") {
        packageName = "com.example.db"
        dialect = "app.cash.sqldelight:sqlite-3-18-dialect:$sqlDelightVersion"
    }
}

kotlin {
  sourceSets {
     val commonMain by getting { 
        dependencies {
                implementation("app.cash.sqldelight:runtime:$sqlDelightVersion")
                implementation("app.cash.sqldelight:primitive-adapters:$sqlDelightVersion")
                implementation("app.cash.sqldelight:coroutines-extensions:$sqlDelightVersion")
       }
     }

    val androidMain by getting {
        dependencies {
            implementation("app.cash.sqldelight:android-driver:$sqlDelightVersion")
        }
     }
   }

   val iosMain by creating {
        dependencies {
          implementation("app.cash.sqldelight:native-driver:$sqlDelightVersion")
        }
   }
}
what am i missing? also which dialect have you successfully tried with KMM ?
k
I’ve never explicitly set the dialect
b
i a wondering what i am missing on my build shared file
k
You’re missing a linker flag to tell the native linker where to find sqlite’s implementation. It’s not really a Kotlin thing. It’s an iOS/llvm thing. The issue I linked to above explains the various places you can set it: https://github.com/cashapp/sqldelight/issues/1442#issuecomment-1048131450. You probably want to add it to Xcode’s “Other Linker Flags” section. The error is coming from the iOS build I assume, since it’s trying to build swift (“LinkDylibError: Failed to build ContentView.swift”).
-lsqlite3
is the flag
b
thank you i had it working by adding
Copy code
targets.filterIsInstance<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>().forEach{
        it.binaries.filterIsInstance<org.jetbrains.kotlin.gradle.plugin.mpp.Framework>()
            .forEach { lib ->
                lib.isStatic = false
                lib.linkerOpts.add("-lsqlite3")
            }
    }
727 Views