I am trying to export my Kotlin Native Multiplatfo...
# kotlin-native
p
I am trying to export my Kotlin Native Multiplatform project as a shared lib, but I am getting these error messages:
Copy code
> Task :windows-framework:linkDebugSharedWindows
Produced library API in nimmstaWindows_api.h
e: Compilation failed: The C:\Users\Patrick\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/clang++ command returned non-zero exit code: 1.
output:
C:\Users\Patrick\AppData\Local\Temp\konan_temp6770444008327035466\api.cpp:355:9: error: unknown type name 'nimmstaWindows_kref_com_soywiz_klock_DateTime'; did you mean 'nimmstaWindows_kref_com_soywiz_korio_file_VfsFile'?
        nimmstaWindows_kref_com_soywiz_klock_DateTime (*get_dateCreated)(nimmstaWindows_kref_WinNimBuildInfo thiz);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        nimmstaWindows_kref_com_soywiz_korio_file_VfsFile
C:\Users\Patrick\AppData\Local\Temp\konan_temp6770444008327035466\api.cpp:242:3: note: 'nimmstaWindows_kref_com_soywiz_korio_file_VfsFile' declared here
} nimmstaWindows_kref_com_soywiz_korio_file_VfsFile;
  ^
C:\Users\Patrick\AppData\Local\Temp\konan_temp6770444008327035466\api.cpp:1061:8: error: unknown type name 'nimmstaWindows_kref_com_soywiz_klock_DateTime'; did you mean 'nimmstaWindows_kref_com_soywiz_korio_file_VfsFile'?
static nimmstaWindows_kref_com_soywiz_klock_DateTime _konan_function_9_impl(nimmstaWindows_kref_WinNimBuildInfo arg0) {
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       nimmstaWindows_kref_com_soywiz_korio_file_VfsFile
C:\Users\Patrick\AppData\Local\Temp\konan_temp6770444008327035466\api.cpp:242:3: note: 'nimmstaWindows_kref_com_soywiz_korio_file_VfsFile' declared here
} nimmstaWindows_kref_com_soywiz_korio_file_VfsFile;
  ^
C:\Users\Patrick\AppData\Local\Temp\konan_temp6770444008327035466\api.cpp:1067:12: error: unknown type name 'nimmstaWindows_kref_com_soywiz_klock_DateTime'; did you mean 'nimmstaWindows_kref_com_soywiz_korio_file_VfsFile'?
  return ((nimmstaWindows_kref_com_soywiz_klock_DateTime){ .pinned = CreateStablePointer(result)});
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           nimmstaWindows_kref_com_soywiz_korio_file_VfsFile
C:\Users\Patrick\AppData\Local\Temp\konan_temp6770444008327035466\api.cpp:242:3: note: 'nimmstaWindows_kref_com_soywiz_korio_file_VfsFile' declared here
} nimmstaWindows_kref_com_soywiz_korio_file_VfsFile;
  ^
3 errors generated.
Any ideas what I need to change? Those are all library classes.
a
Seems interesting. Can you share a reproducer?
p
I have a stack trace, working on the reproducer now
3 errors generated. at org.jetbrains.kotlin.konan.exec.Command.handleExitCode(ExecuteCommand.kt:111) at org.jetbrains.kotlin.konan.exec.Command.execute(ExecuteCommand.kt:72) at org.jetbrains.kotlin.backend.konan.CAdapterCompileKt.produceCAdapterBitcode(CAdapterCompile.kt:14) at org.jetbrains.kotlin.backend.konan.CompilerOutputKt.linkBitcodeDependencies(CompilerOutput.kt:99) at org.jetbrains.kotlin.backend.konan.llvm.BitcodePhasesKt$linkBitcodeDependenciesPhase$1.invoke(BitcodePhases.kt:258) at org.jetbrains.kotlin.backend.konan.llvm.BitcodePhasesKt$linkBitcodeDependenciesPhase$1.invoke(BitcodePhases.kt) at org.jetbrains.kotlin.backend.konan.KonanLoweringPhasesKt$makeKonanModuleOpPhase$1.invoke(KonanLoweringPhases.kt:58) at org.jetbrains.kotlin.backend.konan.KonanLoweringPhasesKt$makeKonanModuleOpPhase$1.invoke(KonanLoweringPhases.kt:56) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper$runBody$1.invoke(CompilerPhase.kt:128) at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.downlevel(CompilerPhase.kt:24) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.runBody(CompilerPhase.kt:127) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.invoke(CompilerPhase.kt:105) at org.jetbrains.kotlin.backend.common.phaser.CompositePhase.invoke(PhaseBuilders.kt:30) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper$runBody$1.invoke(CompilerPhase.kt:128) at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.downlevel(CompilerPhase.kt:24) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.runBody(CompilerPhase.kt:127) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.invoke(CompilerPhase.kt:105) at org.jetbrains.kotlin.backend.common.phaser.CompositePhase.invoke(PhaseBuilders.kt:23) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper$runBody$1.invoke(CompilerPhase.kt:128) at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.downlevel(CompilerPhase.kt:24) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.runBody(CompilerPhase.kt:127) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.invoke(CompilerPhase.kt:105) at org.jetbrains.kotlin.backend.common.phaser.CompositePhase.invoke(PhaseBuilders.kt:30) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper$runBody$1.invoke(CompilerPhase.kt:128) at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.downlevel(CompilerPhase.kt:24) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.runBody(CompilerPhase.kt:127) at org.jetbrains.kotlin.backend.common.phaser.AbstractNamedPhaseWrapper.invoke(CompilerPhase.kt:105) at org.jetbrains.kotlin.backend.common.phaser.CompilerPhaseKt.invokeToplevel(CompilerPhase.kt:42) at org.jetbrains.kotlin.backend.konan.KonanDriverKt.runTopLevelPhases(KonanDriver.kt:28) at org.jetbrains.kotlin.cli.bc.K2Native.doExecute(K2Native.kt:77) at org.jetbrains.kotlin.cli.bc.K2Native.doExecute(K2Native.kt:34) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:85) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:43) at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:105) at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:83) at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:51) at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:219) at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:211) at org.jetbrains.kotlin.cli.bc.K2Native$Companion$main$1.invoke(K2Native.kt:241) at org.jetbrains.kotlin.cli.bc.K2Native$Companion$main$1.invoke(K2Native.kt:238) at org.jetbrains.kotlin.util.UtilKt.profileIf(Util.kt:27) at org.jetbrains.kotlin.util.UtilKt.profile(Util.kt:21) at org.jetbrains.kotlin.cli.bc.K2Native$Companion.main(K2Native.kt:240) at org.jetbrains.kotlin.cli.bc.K2NativeKt.main(K2Native.kt:375) at org.jetbrains.kotlin.cli.utilities.MainKt$main$1.invoke(main.kt:37) at org.jetbrains.kotlin.cli.utilities.MainKt$main$1.invoke(main.kt) at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:17) at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:37)
a
Okay, so you generate this file, and add it to some source set before the actual compilation? I mean, how you’re exporting it? including it into this task
linkDebugSharedWindows
or into the
compileKotlinWindows?
p
I just figured out that it also happens if the file is not generated but is in the path, give me a second
Copy code
package sample

import com.soywiz.klock.DateTime
import kotlin.native.concurrent.ThreadLocal

fun main() {

}

@ThreadLocal
object WinNimBuildInfo {
    val dateCreated: DateTime? = null
}
This is the code I can reduce it to that will throw the error
Copy code
plugins {
    kotlin("multiplatform") version ("1.3.72")
    kotlin("plugin.serialization") version "1.3.72"
}

repositories {
    mavenCentral()
    jcenter()
}

kotlin {

    val ktorVersion = "1.3.2"
    val korioVersion = "1.10.0"
    val serializationVersion = "0.20.0"
    val logbackVersion = "1.2.3"
    val klockVersion = "1.9.1"

    // For ARM, should be changed to iosArm32 or iosArm64
    // For Linux, should be changed to e.g. linuxX64
    // For MacOS, should be changed to e.g. macosX64
    // For Windows, should be changed to e.g. mingwX64
    mingwX64("mingw") {
        binaries {
            executable {
                entryPoint("sample.main")
            }

            sharedLib {
                baseName = "reproducer"
            }
        }
    }

    sourceSets {
        commonMain {
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation("com.soywiz.korlibs.korio:korio:$korioVersion")
                implementation("com.soywiz.korlibs.klock:klock:$klockVersion")
            }
        }
        commonTest {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        mingwX64().compilations["main"].defaultSourceSet {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serializationVersion")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serializationVersion")
            }
        }
        mingwX64().compilations["test"].defaultSourceSet {

        }
    }
}
I think it has something to do with the Nullable export from another library
If I replace
val dateCreated: DateTime? = null
with
val dateCreated: DateTime = DateTime(12313123)
it works
If I replace it with
val dateCreated: Int? = null
it also works
a
Thanks! Now I also see it. Got to dig into for a bit.
p
Thanks for looking into it
a
I managed to minimize the bug, without any third-party libraries use. Now we’re trying to find out, what causes the problem. I mean, why classes from the dependencies do not get into the api, when they’re being used as nullable. Thank you for the report, and much thanks for your patience.
p
Sure, thanks for your help
a
Just FYI, I’ve filed a bug: here.
p
Great, I've put it on my watch list