Kotlin Native "unable to compile c bridges"

I’ve got a build failure that seems like I’m probably just missing a setup step but error-message-Googling has failed me.

I’ve got a pretty standard (AFAICT) multiplatform Gradle build that successfully compiles to (JS, JVM) and successfully runs the tests for those but fails to link and run tests for linuxX64. I am not yet at the stage where I’m linking an executable for main.

I get “e: Unable to compile C bridges” which I’ve not yet diagnosed.

$ gradle linuxMainKlibrary linuxTestKlibrary
# Works fine
$ gradle linkDebugTestLinux --stacktrace --debug
...
2019-12-... [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] 
2019-12-... [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :linkDebugTestLinux
2019-12-... [ERROR] [system.err] e: Unable to compile C bridges
2019-12-... [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
2019-12-... [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with exit value 1 (state: FAILED)
2019-12-... [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Execute compile for :linkDebugTestLinux'
...

The whole --debug dump is available.

I built with this build.gradle but with the marked line uncommented.

$ uname -a
Linux pop-os 5.3.0-7625-generic #27~1576337002~19.10~bc3488b-Ubuntu SMP Sat Dec 14 18:31:03 UTC  x86_64 x86_64 x86_64 GNU/Linux
$ gradle -v

------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------

Build time:   2019-11-18 20:25:01 UTC
Revision:     fad121066a68c4701acd362daf4287a7c309a0f5

Kotlin:       1.3.50
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.5 (Private Build 11.0.5+10-post-Ubuntu-0ubuntu1.1)
OS:           Linux 5.3.0-7625-generic amd64

Hello @mikesamuel! Do you have libncurses5 installed? It’s one of prerequisites of K/N compiler, see here.

1 Like

Thanks much for explaining, and sorry for taking so long to respond.

I installed it and now I get a different, probably unrelated failure which I’ll dig into when I’ve some free cycles; but I think you fixed the problem above.


> Task :compileKotlinLinux
e: Compilation failed: null

 * Source files: EffectSentinel.kt, LawfulEvil.kt, PComparable.kt, RResult.kt, TriState.kt, collections.kt, floatyBits.kt, formatDouble.kt, printErr.kt, CodeGenContext.kt, CodeGenFailure.kt, InfixOperator.kt, MutableBlock.kt, Name.kt, Namer.kt, NodeFactory.kt, OperatorDefinition.kt, PT.kt, PrefixOperator.kt, Property.kt, Simplify.kt, StatementFlow.kt, UsesTemporaries.kt, temporaryToIdentifierPass.kt, CaseBlockBuilder.kt, CaseDecomposition.kt, CaseEffect.kt, CaseIndex.kt, Debug.kt, DebugContext.kt, DecisionTreeBuilder.kt, Decomposer.kt, Failover.kt, PatternContext.kt, Picker.kt, QueryBuilder.kt, Requirement.kt, StringPattern.kt, UrlGlobDecomposer.kt, ValueShape.kt, caseEffectToCode.kt, failoverToRightFactors.kt, initializeTemporaries.kt, inlineRightFactorsIntoDecisionTree.kt, pickerToCode.kt, shapeToPicker.kt, RuntimeType.kt, ConstantValue.kt, ValueLine.kt, ValueLined.kt, ValueRange.kt, ValueRanges.kt, printErrActual.kt
 * Compiler version info: Konan: 1.3.61 / Kotlin: 1.3.60
 * Output kind: LIBRARY

e: kotlin.KotlinNullPointerException
        at org.jetbrains.kotlin.backend.common.lower.IrBuildingTransformer.getBuilder(LowerUtils.kt:132)
        at org.jetbrains.kotlin.backend.konan.lower.BuiltinOperatorLowering.lowerCheckNotNull(BuiltinOperatorLowering.kt:187)
        at org.jetbrains.kotlin.backend.konan.lower.BuiltinOperatorLowering.visitCall(BuiltinOperatorLowering.kt:58)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitCall(IrElementTransformerVoid.kt:170)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitCall(IrElementTransformerVoid.kt:24)
        at org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl.accept(IrCallImpl.kt:89)
        at org.jetbrains.kotlin.ir.expressions.IrExpression$DefaultImpls.transform(IrExpression.kt:28)
        at org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBase.transform(IrExpressionBase.kt:24)
        at org.jetbrains.kotlin.ir.expressions.impl.IrCallWithIndexedArgumentsBase.transformChildren(IrCallWithIndexedArgumentsBase.kt:70)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoidKt.transformChildrenVoid(IrElementTransformerVoid.kt:285)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.transformChildrenVoid(IrElementTransformerVoid.kt:280)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.transformChildren(IrElementTransformerVoid.kt:25)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitExpression(IrElementTransformerVoid.kt:109)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitMemberAccess(IrElementTransformerVoid.kt:163)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitFunctionAccess(IrElementTransformerVoid.kt:166)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitConstructorCall(IrElementTransformerVoid.kt:172)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitConstructorCall(IrElementTransformerVoid.kt:173)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitConstructorCall(IrElementTransformerVoid.kt:24)
        at org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl.accept(IrConstructorCallImpl.kt:32)
        at org.jetbrains.kotlin.ir.expressions.IrExpression$DefaultImpls.transform(IrExpression.kt:28)
        at org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBase.transform(IrExpressionBase.kt:24)
        at org.jetbrains.kotlin.ir.declarations.impl.IrEnumEntryImpl.transformChildren(IrEnumEntryImpl.kt:64)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoidKt.transformChildrenVoid(IrElementTransformerVoid.kt:285)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.transformChildrenVoid(IrElementTransformerVoid.kt:280)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.transformChildren(IrElementTransformerVoid.kt:25)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitDeclaration(IrElementTransformerVoid.kt:46)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitEnumEntry(IrElementTransformerVoid.kt:71)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitEnumEntry(IrElementTransformerVoid.kt:72)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitEnumEntry(IrElementTransformerVoid.kt:24)
        at org.jetbrains.kotlin.ir.declarations.impl.IrEnumEntryImpl.accept(IrEnumEntryImpl.kt:55)
        at org.jetbrains.kotlin.ir.declarations.IrDeclaration$DefaultImpls.transform(IrDeclaration.kt:42)
        at org.jetbrains.kotlin.ir.declarations.impl.IrDeclarationBase.transform(IrDeclarationBase.kt:27)
        at org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl.transformChildren(IrClassImpl.kt:100)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoidKt.transformChildrenVoid(IrElementTransformerVoid.kt:285)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.transformChildrenVoid(IrElementTransformerVoid.kt:280)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.transformChildren(IrElementTransformerVoid.kt:25)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitDeclaration(IrElementTransformerVoid.kt:46)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitClass(IrElementTransformerVoid.kt:49)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitClass(IrElementTransformerVoid.kt:50)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitClass(IrElementTransformerVoid.kt:24)
        at org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl.accept(IrClassImpl.kt:89)
        at org.jetbrains.kotlin.ir.declarations.IrDeclaration$DefaultImpls.transform(IrDeclaration.kt:42)
        at org.jetbrains.kotlin.ir.declarations.impl.IrDeclarationBase.transform(IrDeclarationBase.kt:27)
        at org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl.transformChildren(IrFileImpl.kt:71)
        at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoidKt.transformChildrenVoid(IrElementTransformerVoid.kt:285)
        at org.jetbrains.kotlin.backend.konan.lower.BuiltinOperatorLowering.lower(BuiltinOperatorLowering.kt:47)
        at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$makeIrFilePhase$1.invoke(PhaseBuilders.kt:173)
        at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$makeIrFilePhase$1.invoke(PhaseBuilders.kt:171)
        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:28)
        at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$performByIrFile$1.invoke(PhaseBuilders.kt:144)
        at org.jetbrains.kotlin.backend.common.phaser.PhaseBuildersKt$performByIrFile$1.invoke(PhaseBuilders.kt:136)
        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:28)
        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:28)
        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:28)
        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:27)
        at org.jetbrains.kotlin.cli.bc.K2Native.doExecute(K2Native.kt:74)
        at org.jetbrains.kotlin.cli.bc.K2Native.doExecute(K2Native.kt:34)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:82)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:50)
        at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMainNoExit(CLITool.kt:215)
        at org.jetbrains.kotlin.cli.common.CLITool$Companion.doMain(CLITool.kt:207)
        at org.jetbrains.kotlin.cli.bc.K2Native$Companion$main$1.invoke(K2Native.kt:225)
        at org.jetbrains.kotlin.cli.bc.K2Native$Companion$main$1.invoke(K2Native.kt:222)
        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:224)
        at org.jetbrains.kotlin.cli.bc.K2NativeKt.main(K2Native.kt:304)
        at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:16)


> Task :compileKotlinLinux FAILED

FAILURE: Build failed with an exception.

Glad to know that the first is gone now. About this one. First of all you can try to update the compiler version, as we already have 1.3.70 released. If it won’t help, feel free to share the code here, or any other way you want.

1 Like

Thanks, Artyom,

I updated to 1.3.70 and get a similar problem: Gradle scan

14:39:35.215 [ERROR] [system.err] Caused by: kotlin.KotlinNullPointerException
14:39:35.215 [ERROR] [system.err]       at org.jetbrains.kotlin.backend.common.lower.IrBuildingTransformer.getBuilder(LowerUtils.kt:129)
14:39:35.215 [ERROR] [system.err]       at org.jetbrains.kotlin.backend.konan.lower.BuiltinOperatorLowering.lowerCheckNotNull(BuiltinOperatorLowering.kt:187)
...

which seems to refer to LowerUtils.kt L126-129. I’m not familiar with Kotlin’s compiler but I imagine most non-trivial source files probably involve bultin operators that get lowered.

I tried to comment out entire files to see if it passes on a subset, but could not get a smaller repro case, except I ruled out all the test files: src/*Test/**.kt

The following should let you reproduce my problem

git clone 'https://gitlab.com/temper-lang/pattern.git'

cd pattern

git checkout e3033d640bf4320eb7a962a646dfecd1f1fb7d0a

cat <<ENDOFPATCH | patch -p1
diff --git a/build.gradle b/build.gradle
index 35435bd..904d80b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,5 @@
 plugins {
-    id 'org.jetbrains.kotlin.multiplatform' version '1.3.61'
+    id 'org.jetbrains.kotlin.multiplatform' version '1.3.70'
     id 'org.jlleitschuh.gradle.ktlint' version '9.1.1'
     id 'io.gitlab.arturbosch.detekt' version '1.2.2'
     id 'org.jetbrains.dokka' version '0.10.1'
@@ -37,12 +37,12 @@ kotlin {
     // 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
-  //linuxX64('linux')
+    linuxX64('linux')
     sourceSets {
         commonMain {
             dependencies {
                 implementation kotlin('stdlib-common')
-                implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.61'
+                implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.70'
             }
         }
         commonTest {
ENDOFPATCH

gradle compileKotlinLinux --debug --stacktrace

Oh. I use gradle in the repro steps above but gradle on my setup looks for a gradlew so I actually am invoking gradle the standard way and the step:

git checkout e3033d640bf4320eb7a962a646dfecd1f1fb7d0a

gets the most recent commit as of when I published those steps but I’ve never successfully built with the native backend so that’s probably not the commit that added whatever is interacting badly.

Whatever the issue is, it seems fixed in Kotlin 1.4-M2.

I got the original issue too, but needed a different solution. Running on Fedora, I wasn’t able to solve it by installing ncurses-devel, I needed to install ncurses-compat-devel too.