kotlinkotlin-nativecinterop

Where to find (install) Kotlin cinterop tool on Mac


I would like to try to build Kotlin/Native project with dependencies on some library. As documentation explains, I need to create def file (which I was already created) and run cinterop tool.

However, I wasn't able to find this tool on my Mac and curious how this could be installed.

Can you please give me some advice?


Solution

  • I strongly advise you to use Gradle + Kotlin MPP plugin. Not only it will provide cinterop support, but it will ease further development, testing, and multiplatform support. It works on any OS, of course.

    If you need an example, here is the official one for the cURL library: https://github.com/JetBrains/kotlin-native/blob/master/samples/libcurl/build.gradle.kts. Note the cinterops block under compilations["main"].

    The nice thing about Kotlin MPP plugin is that it actually allows you to play with the Kotlin/Native tools directly. It will download the tools specifically for your platform automatically on the first run and place them in ~/.konan directory. So if you really want to use cinterop tool from CLI you'll be able to find it there: ~/.konan/kotlin-native-macos-1.3.61/bin/cinterop. klib and kotlinc are there as well.