is there a way to add custom linker flags to a tes...
# kotlin-native
k
is there a way to add custom linker flags to a test binary in mpp projects? seems like
linkerOpts
inside the test
KotlinNativeCompilation
are ignored when it comes to linking the test debug executable.
d
Had a similar issue. Solved it by moving the linkerOpts into the def file.
k
indeed, it picks up the flags in the def file. unfortunately im trying to reconfigure a .klib that was published to maven, so i can't access the .def file. looks like whatever flags that are chosen in the .def file are pushed into the klib at publish time, and i can't find a way to override or add to them locally.
a workaround might be to create a stub def for a dummy package that has just my flag in it... but thats pretty ugly
d
You can add to the linkerOpts of the executable. I have done this before to specify where the linker should look for the klib's requested libraries.
Which flags in particular are you trying to override?
k
I need to do exactly that, add a -L flag telling it where to look for the klib's cinterop artifacts. it ignores
linkerOpts
passed to the
KotlinNativeCompilation
for me.
i
@kyonifer What Kotlin version do you use? In
1.3.11
adding options in a test compilation works fine for my playground project but
1.3.20 EAP2
does have a bug preventing it: https://youtrack.jetbrains.com/issue/KT-29254. If you use
1.3.20 EAP2
, you can specify these options using the binaries DSL:
Copy code
kotlin {
    targets {
        fromPreset(presets.macosX64, 'macos') {
            binaries.getExecutable('test', 'DEBUG').linkerOpts = ['-L/path/to/libraries']
        }
    }
}
k
I was using an EAP so thats probably it. I missed that issue and the new DSL. I'll give the binaries DSL a shot, thanks!