https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Skolson5903

08/31/2020, 5:44 PM
I'm using kotlin 1.4.0 and a multiplatform project using cinterop. Given an example target specified like this:
Copy code
mingwX64 {
        compilations.getByName("main") {
            val myInterop by cinterops.creating {
                defFile("some.def")
                packageName("com.whatever")
                compilerOpts("-I$someIncludePath")
                //... whatever else ...
            }
        }
    }
and a nativeMain sourceset that needs to depend on the output from the mingw64 main compilation cinterop library it generates, what's the best way to specify that dependency? The sourceset name for the above compilation is "mingwX64Main", so I tried this:
Copy code
val mingwX64Main by getting
        val nativeMain by getting {
            dependsOn(mingwX64Main)
        }
but no luck. There's no explicit source in that sourceset, just the generated external library from cinterop, which dependsOn doesn't see. The only way I've gotten nativeMain source to see the stuff generated by cinterop is by adding this to the compilation:
Copy code
defaultSourceSet {
               kotlin.srcDir("src/nativeMain/kotlin")
            }
which points the mingwX64Main sourceset to the same source directory as nativeMain. This allows imports etc to work in nativeMain source. But it seems kludgy as it gets a gradle warning on every sync:
Copy code
Duplicate content roots detected: (text about nativeMain and mingwX64Main sourcesets overlapping)
Seems like there should be a dependsOn or a dependencies clause to explicitly declare this. Anybody got suggestions? Something like:
Copy code
val nativeMain by getting {
            dependencies {
                implementation(<ref to the cinterop library produced from compilation mingwX64 main, sourceset mingwX64Main>)
            }
        }
Or any other way that doesn't get warnings on every sync :-) Thanks in advance for any help...
k

Kris Wong

08/31/2020, 5:52 PM
why create a target just to wrap a cinterop?
s

Skolson5903

08/31/2020, 6:09 PM
The sample I was following originally had it that way 🙂. Where else is the cinterops clause supported for use? After seeing your note I tried different things in the nativeMain sourceset with no luck. Is there a sample or doc you could point me to?
k

Kris Wong

08/31/2020, 6:10 PM
any native target supports cinertop
s

Skolson5903

08/31/2020, 6:11 PM
I'm confused. mingw64 is one of the targets I'm doing this for, it's just the first I'm trying to get working.
So far I only have the windows flavor of the C library built cinterop is using.
s

Skolson5903

08/31/2020, 6:17 PM
Thanks, already been there but I think I see what your saying. I stopped using the default nativeMain sourceset, moved the source to mingwX64Main, and all is well. Thanks!
🍻 1
2 Views