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.kiProduces four files:
| File | Contents |
|---|---|
mylib.c | C source (all functions, no main wrapper) |
mylib.h | C header with #include guard and typed function declarations |
mylib.kl | Klar extern block ready to paste into a Klar project |
mylib.json | JSON type manifest for tooling and AI agents |
Type Mapping
All public, non-main functions are exported. Parameter and return types are mapped:
| Kira | C | Klar |
|---|---|---|
i32 | int32_t | i32 |
i64 | int64_t | i64 |
f64 | double | f64 |
bool | bool | Bool |
string | const char* | CStr |
void | void | Void |
Workflow: Calling Kira from Klar
- Write a Kira library module:
// mylib.ki
pub fn add(a: i32, b: i32) -> i32 {
return a + b
}- Build with
--lib:
kira build --lib mylib.ki- Compile the generated C to an object file:
cc -c mylib.c -o mylib.o- In your Klar project, include the generated
mylib.klextern block and link againstmylib.o.
Compiling Generated C
The generated C code requires the Boehm GC library:
# macOS
brew install bdw-gc
# Linux (Debian/Ubuntu)
apt install libgc-devCompile a standalone program:
cc -o myapp myapp.c -lm -lgcWithout GC
If libgc is unavailable, compile with -DKIRA_NO_GC:
cc -o myapp myapp.c -lm -DKIRA_NO_GC