Skip to main content
Kira

Building Libraries

Kira modules can be compiled as libraries for consumption by other languages (notably Klar) via the C ABI.

--lib Flag

kira build --lib mylib.ki

Produces four files:

FileContents
mylib.cC source (all functions, no main wrapper)
mylib.hC header with #include guard and typed function declarations
mylib.klKlar extern block ready to paste into a Klar project
mylib.jsonJSON type manifest for tooling and AI agents

Type Mapping

All public, non-main functions are exported. Parameter and return types are mapped:

KiraCKlar
i32int32_ti32
i64int64_ti64
f64doublef64
boolboolBool
stringconst char*CStr
voidvoidVoid

Workflow: Calling Kira from Klar

  1. Write a Kira library module:
// mylib.ki
pub fn add(a: i32, b: i32) -> i32 {
    return a + b
}
  1. Build with --lib:
kira build --lib mylib.ki
  1. Compile the generated C to an object file:
cc -c mylib.c -o mylib.o
  1. In your Klar project, include the generated mylib.kl extern block and link against mylib.o.

Compiling Generated C

The generated C code requires the Boehm GC library:

# macOS
brew install bdw-gc

# Linux (Debian/Ubuntu)
apt install libgc-dev

Compile a standalone program:

cc -o myapp myapp.c -lm -lgc

Without GC

If libgc is unavailable, compile with -DKIRA_NO_GC:

cc -o myapp myapp.c -lm -DKIRA_NO_GC