Silent error when using zig-sqlite

Hi, I’m using zig-sqlite in a personal project, and I’ve run into a weird error when I try to use the library.
The following code:

const std = @import("std");
const sqlite = @import("sqlite");

pub fn main() !void {
    var db = try sqlite.Db.init(.{
        .mode = sqlite.Db.Mode{ .File = "test.db" },
        .open_flags = .{
            .write = true,
            .create = true,
        },
        .threading_mode = .MultiThread,
    });

    _ = &db;
    std.debug.print("Hello World!\n", .{});
}

compile and runs fine. But as soon as I try to do something with my database, say

const std = @import("std");
const sqlite = @import("sqlite");

pub fn main() !void {
    var db = try sqlite.Db.init(.{
        .mode = sqlite.Db.Mode{ .File = "test.db" },
        .open_flags = .{
            .write = true,
            .create = true,
        },
        .threading_mode = .MultiThread,
    });

    try db.exec("CREATE TABLE IF NOT EXISTS employees(id integer primary key, name text, age integer, salary integer)", .{}, .{});
    std.debug.print("Hello World!\n", .{});
}

then the program does not compile anymore, and I get this:

install
└─ install zig_sqlite_compile_error
   └─ compile exe zig_sqlite_compile_error Debug native failure
error: process terminated unexpectedly
failed command: /nix/store/m26qygj7anp8sknmccph6fh5lsz2a6z2-zig-0.16.0-dev.923+06d9e3bc0/bin/zig build-exe -ODebug --dep sqlite -Mroot=/home/arthur/dev/tests/zig_sqlite_compile_error/src/main.zig .zig-cache/o/6cd11c7fd78fe06afb19f9d74d36cc91/libsqlite.a -I /home/arthur/.cache/zig/p/sqlite-3.48.0-F2R_a5yODgDFvwwsytm7ZONcSqYBo3qv1PmXOtw3tqLA/c -I /home/arthur/.cache/zig/p/N-V-__8AAH-mpwB7g3MnqYU-ooUBF1t99RP27dZ9addtMVXD/. -I .zig-cache/o/d511c02291e66c9e2f91216b9ea9dbbd -Msqlite=/home/arthur/.cache/zig/p/sqlite-3.48.0-F2R_a5yODgDFvwwsytm7ZONcSqYBo3qv1PmXOtw3tqLA/sqlite.zig -lc --cache-dir .zig-cache --global-cache-dir /home/arthur/.cache/zig --name zig_sqlite_compile_error --zig-lib-dir /nix/store/m26qygj7anp8sknmccph6fh5lsz2a6z2-zig-0.16.0-dev.923+06d9e3bc0/lib/ --listen=-

Build Summary: 2/5 steps succeeded (1 failed)
install transitive failure
└─ install zig_sqlite_compile_error transitive failure
   └─ compile exe zig_sqlite_compile_error Debug native failure

error: the following build command failed with exit code 1:
.zig-cache/o/927472207b3ef0a03db7417ea1862ebc/build /nix/store/m26qygj7anp8sknmccph6fh5lsz2a6z2-zig-0.16.0-dev.923+06d9e3bc0/bin/zig /nix/store/m26qygj7anp8sknmccph6fh5lsz2a6z2-zig-0.16.0-dev.923+06d9e3bc0/lib /home/arthur/dev/tests/zig_sqlite_compile_error .zig-cache /home/arthur/.cache/zig --seed 0x9ed77e3d -Z5e09ce6393d1de78

I’m not sure how to interpret this error. I’m on the latest version of git (0.16.0-dev.923+06d9e3bc0). I also had the same error on 0.15.2.

Well, I should have looked a little harder for a solution.
This is a duplicate of this issue. The fix is to add .use_llvm = true to the addExecutable call.

1 Like