Multiplatform configuration for windows and linux sharing same cinterop definitions

Hello, I would like to ask what is the preffered way for defining two targets (linuxX64 and mingwX64) with a shared sourceSet with an cinterop definition.
The problem is that when I define the cinterops separately for each target and then put some common code into either the predefined commonMain or any other custom shared sourceSet the two target’s implicit sourceSets are depending on, the IDE doesn’t recognize that the shared source set is ment to be Kotlin/Native and that it fails to resolve the kotlinx.cinterop and the referenced C libraries and everything in that shared source set is red. Even though it’s still possible to build it with Konanc.


1 Like

Unfortunately, there is no option to provide a shared sourceSet for such case. This can change in future, but I cannot give any ETA for now.

Hi, has anything changed in this area?

Sure, I for example defined cinterop for linux and mingw targets:

    ).forEach {
        it.apply {
            compilations.getByName("main") {
                cinterops {
                    val jvmti by creating
            binaries {
                sharedLib {
                    baseName = "native"

and then set kotlin.mpp.enableCInteropCommonization=true in, after that I was able to use my C library in common code.

1 Like