I’m trying to build a simple objective c library f...
# kotlin-native
a
I’m trying to build a simple objective c library from it’s original source and generate bindings for it... I got the bindings to build, but when I try to build my app on the iOS simulator I get this message:
Copy code
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_Reachability", referenced from:
      objc-class-ref in result.o
ld: symbol(s) not found for architecture x86_64
I’m thinking it has something to do with building from a .m and .h file and it not being a dynamic library, so the binaries are not included, but I’m not sure how to include them here’s my def in my build.gradle.kts:
Copy code
iosX64("ios") {
            compilations.getByName("main") {
                val reachabilityInterop by cinterops.creating {
                    defFile(project.file("src/nativeInterop/Reachability.def"))
                    val headerPath = project.file("src/nativeInterop/Reachability/").absoluteFile
                    compilerOpts("-I${headerPath}", "-L${headerPath}")
                }
            }
        }
k
It's definitely that the linker can't find the binary. That's what
Undefined symbols
is upset about. I don't think the Kotlin gradle build has a way of building your Objc source automatically, so you'll need to create a binary from that first. I'd probably build a static archive
.a
file and link to that, for simplicity. I don't have simple build steps available, but I'd start digging around stuff like https://stackoverflow.com/questions/4654534/how-to-build-an-objective-c-static-library and https://www.raywenderlich.com/2658-creating-a-static-library-in-ios-tutorial. Once you get an
.a
file with the needed architectures (probably x64 and arm64), you'll need to tell the Kotlin compiler to link to that.
🙌 1
a
@kpgalligan You are a life saver! Thank you so much for the response.
That is what i suspected… but I’ve not done much with objective C in the past, so I was not sure. Thanks again for your help
👍 1