Cross Compiling with C dependencies

Hi, my intention is to create binaries as releases for different targets, I depend on a library that is a wrapper for lmdb, when I build not trying other target, I get no errors; I’m on Linux Debian and have the distro lmdb-dev package.

My zig.zon has the following

.dependencies = .{
        .@"lmdb-zig" = .{
            .url = "https://github.com/john-g4lt/lmdb-zig/archive/refs/tags/v0.1.0.tar.gz",
            .hash = "1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97",
        },
        .clap = .{
            .url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.9.1.tar.gz",
            .hash = "122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b",
        },
    },

My build.zig is including lmdb :

    const lib = b.addStaticLibrary(.{
        .name = "tldrtranslate",
        .root_source_file = b.path("src/tldr-base.zig"),
        .target = target,
        .optimize = optimize,
    });

    const lmdb_zig = b.dependency("lmdb-zig", .{ .target = target, .optimize = optimize });
    lib.linkLibrary(lmdb_zig.artifact("lmdb-zig"));

    b.installArtifact(lib);

    const clap = b.dependency("clap", .{});

    const exe = b.addExecutable(.{
        .name = "tldrtranslate",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("lmdb-zig", lmdb_zig.module("lmdb-zig-mod"));
    exe.root_module.addImport("clap", clap.module("clap"));
    exe.linkLibrary(lmdb_zig.artifact("lmdb-zig"));

    b.installArtifact(exe);

When I issue:

zig build --release=small -Dtarget=x86_64-native

My zig-out looks like

$ tree zig-out/
zig-out/
β”œβ”€β”€ bin
β”‚   └── tldrtranslate
└── lib
    β”œβ”€β”€ libtldrtranslate.a
    └── tldrtranslate.lib

zig version is 0.13.0

But when I try

zig build --release=small -Dtarget=x86_64-linux

I get

install
└─ install tldrtranslate
   └─ zig build-exe tldrtranslate ReleaseSmall x86_64-linux 2 errors
/home/igor/.cache/zig/p/1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97/lmdb.zig:3:15: error: C import failed
pub const c = @cImport(@cInclude("lmdb.h"));
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    Flags_Open: /home/igor/.cache/zig/p/1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97/lmdb.zig:73:15
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
/home/igor/playground/zig/tldrtranslate/.zig-cache/o/db7c6f3eac2005dc9bdd2050535739fd/cimport.h:1:10: error: 'lmdb.h' file not found
#include <lmdb.h>
         ^
error: the following command failed with 2 compilation errors:
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-exe /home/igor/playground/zig/tldrtranslate/.zig-cache/o/2f5c162fb8342cdcc282be84e2b526cf/liblmdb-zig.a -OReleaseSmall -target x86_64-linux -mcpu baseline -I /home/igor/playground/zig/tldrtranslate/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 --dep lmdb-zig --dep clap -Mroot=/home/igor/playground/zig/tldrtranslate/src/main.zig -I /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110 -Mlmdb-zig=/home/igor/.cache/zig/p/1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97/lmdb.zig -Mclap=/home/igor/.cache/zig/p/122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b/clap.zig -lc --cache-dir /home/igor/playground/zig/tldrtranslate/.zig-cache --global-cache-dir /home/igor/.cache/zig --name tldrtranslate --listen=- 
Build Summary: 4/7 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install tldrtranslate transitive failure
   └─ zig build-exe tldrtranslate ReleaseSmall x86_64-linux 2 errors
error: the following build command failed with exit code 1:
/home/igor/playground/zig/tldrtranslate/.zig-cache/o/77f05256a4e3ee58b1da8cc9dd4c36bb/build /home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig /home/igor/playground/zig/tldrtranslate /home/igor/playground/zig/tldrtranslate/.zig-cache /home/igor/.cache/zig --seed 0xda6818d -Zfc4c5ea5d8e0cd72 --release=small -Dtarget=x86_64-linux

What am I missing?

And later one to automate the release, what is the preferred way to do so? Is it with additional steps in the build process? If this is the case, maybe is there a template for that purpose?

1 Like

You can use --verbose option to show full arguments passed.

zig build --release=small -Dtarget=x86_64-linux --verbose

The -I option is a include path.
Zig will be able to find lmdb.h from include paths.

It seems that john-g4lt/lmdb-zig is not published lmdb.h.

I don’t know why x86_64-native target is built successfully.

1 Like

It probably builds for native because the lmdb.h header exists in the system include path.

1 Like

What I see about .h files is this

$ zig build --release=small -Dtarget=x86_64-native --verbose
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-lib -cflags -fno-sanitize=undefined -- /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110/libraries/liblmdb/mdb.c /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110/libraries/liblmdb/midl.c -OReleaseSmall -target x86_64-native -mcpu baseline -Mroot -lc --cache-dir /home/igor/playground/zig/tldrtranslate/.zig-cache --global-cache-dir /home/igor/.cache/zig --name lmdb-zig -static --listen=- 
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-exe /home/igor/playground/zig/tldrtranslate/.zig-cache/o/bcccaffbf139948040a2d45decbad4da/liblmdb-zig.a -OReleaseSmall -target x86_64-native -mcpu baseline -I /home/igor/playground/zig/tldrtranslate/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 --dep lmdb-zig --dep clap -Mroot=/home/igor/playground/zig/tldrtranslate/src/main.zig -I /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110 -Mlmdb-zig=/home/igor/.cache/zig/p/1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97/lmdb.zig -Mclap=/home/igor/.cache/zig/p/122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b/clap.zig -lc --cache-dir /home/igor/playground/zig/tldrtranslate/.zig-cache --global-cache-dir /home/igor/.cache/zig --name tldrtranslate --listen=- 
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-lib -OReleaseSmall -target x86_64-native -mcpu baseline -I /home/igor/playground/zig/tldrtranslate/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 -Mroot=/home/igor/playground/zig/tldrtranslate/src/tldr-base.zig -lc --cache-dir /home/igor/playground/zig/tldrtranslate/.zig-cache --global-cache-dir /home/igor/.cache/zig --name tldrtranslate -static --listen=- 
i@h:tldrtranslate$ cd .zig-cache/
i@h:.zig-cache$ for i in $(fd -e h); do echo $i; cat $i ; done
o/1cf524f1ac1ae61dd7528ab970008b0a/cimport.h
#include <lmdb.h>
o/1e048b680110acc5abe49ebee169ae95/cimport.h
#include <lmdb.h>
o/3d80f0b44e210ad1b694186406a00d27/cimport.h
#include <lmdb.h>
o/430936501b64f72def6ae40ce85b0a5f/cimport.h
#include <lmdb.h>
o/45810067a73c944ee8b7c47c29ce9519/cimport.h
#include <lmdb.h>
o/ab1f1d7f2d9752cddd86ad774294f312/cimport.h
#include <lmdb.h>
o/db7c6f3eac2005dc9bdd2050535739fd/cimport.h
#include <lmdb.h>
o/dd10476123146087dadcbbbed71bf51d/cimport.h
#include <lmdb.h>

I took a look at other libraries in github like GitHub - allyourcodebase/lmdb: Lmdb using the zig build system and they do not offer the lmdb.h library either.

According to Zig Package Manager 2 - WTF is Build.Zig.Zon and Build.Zig (0.11.0 Update) - Zig NEWS if I understood correctly, from 0.11.0 there is no need to include things from the c thing. There are more than 6 different repos offering lmdb from zig, but this one was the one that worked when I tried. If the .h needs to be included in john’s lib, would it suffice to put it in the root dir and include in the zig.zon file ?

That allyourcodebase/lmdb package is translating the lmdb.h C header into Zig and providing that in a Zig module, no lmdb.h required since it has been translated into Zig. The package you are using is providing a lmdb Zig module that imports the lmdb.h file, but the build.zig does not publish that lmdb.h file and therefore it doesn’t work.

Your include paths are:

  • /home/igor/playground/zig/tldrtranslate/.zig-cache/o/544790c738d38eb183fa637997b2e9c3
  • /home/igor/.cache/zig/ p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110
  • /home/igor/playground/zig/tldrtranslate/.zig-cache/o/544790c738d38eb183fa637997b2e9c3

where do you locate lmdb.h?

Work around:
You can explicitly add include path to resolve it.

build.zig

exe.addIncludePath("/path/to"); // suppose to locate /path/to/lmdb.h

I tried adding

exe.addIncludePath(b.path(""));

To my build.zig, now the build throws

$ zig build --release=small -Dtarget=x86_64-linux --verbose
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-lib -cflags -fno-sanitize=undefined -- /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110/libraries/liblmdb/mdb.c /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110/libraries/liblmdb/midl.c -OReleaseSmall -target x86_64-linux -mcpu baseline -Mroot -lc --cache-dir /home/igor/playground/zig/tldrtranslate/.zig-cache --global-cache-dir /home/igor/.cache/zig --name lmdb-zig -static --listen=- 
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-lib -OReleaseSmall -target x86_64-linux -mcpu baseline -I /home/igor/playground/zig/tldrtranslate/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 -Mroot=/home/igor/playground/zig/tldrtranslate/src/tldr-base.zig -lc --cache-dir /home/igor/playground/zig/tldrtranslate/.zig-cache --global-cache-dir /home/igor/.cache/zig --name tldrtranslate -static --listen=- 
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-exe /home/igor/playground/zig/tldrtranslate/.zig-cache/o/2f5c162fb8342cdcc282be84e2b526cf/liblmdb-zig.a -OReleaseSmall -target x86_64-linux -mcpu baseline -I /home/igor/playground/zig/tldrtranslate/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 -I /home/igor/playground/zig/tldrtranslate --dep lmdb-zig --dep clap -Mroot=/home/igor/playground/zig/tldrtranslate/src/main.zig -I /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110 -Mlmdb-zig=/home/igor/.cache/zig/p/1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97/lmdb.zig -Mclap=/home/igor/.cache/zig/p/122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b/clap.zig -lc --cache-dir /home/igor/playground/zig/tldrtranslate/.zig-cache --global-cache-dir /home/igor/.cache/zig --name tldrtranslate --listen=- 
install
└─ install tldrtranslate
   └─ zig build-exe tldrtranslate ReleaseSmall x86_64-linux 2 errors
/home/igor/.cache/zig/p/1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97/lmdb.zig:3:15: error: C import failed
pub const c = @cImport(@cInclude("lmdb.h"));
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    Flags_Open: /home/igor/.cache/zig/p/1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97/lmdb.zig:73:15
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
/home/igor/playground/zig/tldrtranslate/.zig-cache/o/db7c6f3eac2005dc9bdd2050535739fd/cimport.h:1:10: error: 'lmdb.h' file not found
#include <lmdb.h>
         ^
error: the following command failed with 2 compilation errors:
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-exe /home/igor/playground/zig/tldrtranslate/.zig-cache/o/2f5c162fb8342cdcc282be84e2b526cf/liblmdb-zig.a -OReleaseSmall -target x86_64-linux -mcpu baseline -I /home/igor/playground/zig/tldrtranslate/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 -I /home/igor/playground/zig/tldrtranslate --dep lmdb-zig --dep clap -Mroot=/home/igor/playground/zig/tldrtranslate/src/main.zig -I /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110 -Mlmdb-zig=/home/igor/.cache/zig/p/1220a44f2880d150589664ee936da3b856674d732cbf02b4714a7282fa752facad97/lmdb.zig -Mclap=/home/igor/.cache/zig/p/122062d301a203d003547b414237229b09a7980095061697349f8bef41be9c30266b/clap.zig -lc --cache-dir /home/igor/playground/zig/tldrtranslate/.zig-cache --global-cache-dir /home/igor/.cache/zig --name tldrtranslate --listen=- 
Build Summary: 4/7 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install tldrtranslate transitive failure
   └─ zig build-exe tldrtranslate ReleaseSmall x86_64-linux 2 errors
error: the following build command failed with exit code 1:
/home/igor/playground/zig/tldrtranslate/.zig-cache/o/f45e36411437794710c18c22195e71c9/build /home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig /home/igor/playground/zig/tldrtranslate /home/igor/playground/zig/tldrtranslate/.zig-cache /home/igor/.cache/zig --seed 0xfdfe055f -Z3c11cd4333a5b061 --release=small -Dtarget=x86_64-linux --verbose

In the other hand, trying to cross-compile the library, which also fails, I have tried the following:

The files look like

lmdb-zig$ tree
.
β”œβ”€β”€ build.zig
β”œβ”€β”€ build.zig.zon
β”œβ”€β”€ example.zig
β”œβ”€β”€ LICENSE
β”œβ”€β”€ lmdb.h
β”œβ”€β”€ lmdb.zig
β”œβ”€β”€ README.md

I added manually the lmdb.h and modified the build.zig.zon to include the header as in

.{
.
.
.
    .paths = .{
        "build.zig",
        "build.zig.zon",
        "lmdb.zig",
        "example.zig",
        "LICENSE",
        "README.md",
        "lmdb.h",
    },
}

To the build.zig lib I added a line to include the lmdb.h

     mod.addIncludePath(dep_lmdb_c.path(""));
+    mod.addIncludePath(b.path(""));

And I get

lmdb-zig$ zig build -Dtarget=x86_64-linux --verbose -freference-trace
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-lib -freference-trace=256 -cflags -fno-sanitize=undefined -- /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110/libraries/liblmdb/mdb.c /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110/libraries/liblmdb/midl.c -ODebug -target x86_64-linux -mcpu baseline -Mroot -lc --cache-dir /home/igor/playground/zig/lmdb-zig/.zig-cache --global-cache-dir /home/igor/.cache/zig --name lmdb-zig -static --listen=- 
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig test -freference-trace=256 /home/igor/playground/zig/lmdb-zig/.zig-cache/o/2fcf90e4dbf64bff49ca869aa337b208/liblmdb-zig.a -ODebug -target x86_64-linux -mcpu baseline -I /home/igor/playground/zig/lmdb-zig/lmdb/libraries/liblmdb -I /home/igor/playground/zig/lmdb-zig/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 -Mroot=/home/igor/playground/zig/lmdb-zig/lmdb.zig -lc --cache-dir /home/igor/playground/zig/lmdb-zig/.zig-cache --global-cache-dir /home/igor/.cache/zig --name test --listen=- 
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig build-exe -freference-trace=256 /home/igor/playground/zig/lmdb-zig/.zig-cache/o/2fcf90e4dbf64bff49ca869aa337b208/liblmdb-zig.a -ODebug -target x86_64-linux -mcpu baseline -I /home/igor/playground/zig/lmdb-zig/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 --dep lmdb-zig -Mroot=/home/igor/playground/zig/lmdb-zig/example.zig -I /home/igor/.cache/zig/p/12209bfdbf43d479c2cac0ca2212853ab2136f1621f49461f62c7932a7819bc29110 -I /home/igor/playground/zig/lmdb-zig -Mlmdb-zig=/home/igor/playground/zig/lmdb-zig/lmdb.zig -lc --cache-dir /home/igor/playground/zig/lmdb-zig/.zig-cache --global-cache-dir /home/igor/.cache/zig --name example --listen=- 
install
└─ install test
   └─ zig test Debug x86_64-linux 2 errors
lmdb.zig:3:15: error: C import failed
pub const c = @cImport(@cInclude("lmdb.h"));
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    Flags_Open: lmdb.zig:73:15
/home/igor/playground/zig/lmdb-zig/.zig-cache/o/2887b1334726e61eb7a08db569f58fee/cimport.h:1:10: error: 'lmdb.h' file not found
#include <lmdb.h>
         ^
error: the following command failed with 2 compilation errors:
/home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig test -freference-trace=256 /home/igor/playground/zig/lmdb-zig/.zig-cache/o/2fcf90e4dbf64bff49ca869aa337b208/liblmdb-zig.a -ODebug -target x86_64-linux -mcpu baseline -I /home/igor/playground/zig/lmdb-zig/lmdb/libraries/liblmdb -I /home/igor/playground/zig/lmdb-zig/.zig-cache/o/544790c738d38eb183fa637997b2e9c3 -Mroot=/home/igor/playground/zig/lmdb-zig/lmdb.zig -lc --cache-dir /home/igor/playground/zig/lmdb-zig/.zig-cache --global-cache-dir /home/igor/.cache/zig --name test --listen=- 
Build Summary: 5/8 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install test transitive failure
   └─ zig test Debug x86_64-linux 2 errors
error: the following build command failed with exit code 1:
/home/igor/playground/zig/lmdb-zig/.zig-cache/o/70561af21c0ed3680df102cf13f2e50d/build /home/igor/playground/zig/zig-linux-x86_64-0.13.0/zig /home/igor/playground/zig/lmdb-zig /home/igor/playground/zig/lmdb-zig/.zig-cache /home/igor/.cache/zig --seed 0x8dba2600 -Zb4d4bfb64467d181 -Dtarget=x86_64-linux --verbose -freference-trace

Any other things to try before pointing to another library option? If better trying another library for lmd, what would be the suggestion?

What would be a good resource to understand better the zig build system? So far I didn’t see in Zig Build System ⚑ Zig Programming Language some help for this particular case. Some other references where pointing to prior versions of zig.

Thanks for the help, so far :pray:

I can not reproduce this issue.
Probably, it seems to affect main.zig and/or tldr-base.zig

Would you like provide a minimum example?

1 Like

Sure, here it is a minimal sample, the only requirement is to create a directory called tldr_translation_db from where your are running the sample

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

pub fn main() !void {
    const env = try lmdb.Env.init("tldr_translation_db", .{});
    defer env.deinit();

    const tx = try env.begin(.{});
    errdefer tx.deinit();
    const db = try tx.open(null, .{});
    defer db.close(env);
    const word = "caminar";
    try tx.put(db, word, "camina", .{});
    const conjugation = tx.get(db, "caminar") catch "caminar";
    std.debug.print("{s} -> {s}\n", .{ word, conjugation });
}

Thank you :).

I forked the library and put some attempts to overcome the issues here.

My build.zig looks like

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});

    const optimize = b.standardOptimizeOption(.{});

    const lmdb = b.dependency("lmdb", .{});
    const exe = b.addExecutable(.{
        .name = "simple",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("lmdb", lmdb.module("lmdb-zig-mod"));
    exe.linkLibrary(lmdb.artifact("lmdb-zig"));
    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);

    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

and my build.zig.zon is now

.{
    .name = "lmdbsample",

    .version = "0.0.0",

    .dependencies = .{
        .lmdb = .{
            .url = "https://github.com/ikks/lmdb-zig/archive/3d27b4e4900ded264e6530cc0376aac69b52600d.tar.gz",
            .hash = "1220f365e31eda77f58eb6c6a6bbab0680d5bf092346c95f8b5b923772ac5562010b",
        },
    },
    .paths = .{
        "build.zig",
        "build.zig.zon",
        "src",
    },
}

And when running the sample the expected output would be:

$ zig-out/bin/simple 
caminar -> camina

Firstly, this is ikks/lmdb-zig bug !

The module lmdb-zig-mod is not appropriately specified include path.

Probably, it should look like this:

    const lib = b.addStaticLibrary(.{ .name = "lmdb-zig", .target = target, .optimize = optimize });
    const dep_lmdb_c = b.dependency("lmdb_c", .{ .target = target, .optimize = optimize });
    lib.addCSourceFiles(.{ .root = dep_lmdb_c.path("libraries/liblmdb"), .files = &.{ "mdb.c", "midl.c" }, .flags = &.{"-fno-sanitize=undefined"} });
    lib.linkLibC();
+   lib.installHeader(dep_lmdb_c.path("libraries/liblmdb/lmdb.h"), "lmdb.h");
    b.installArtifact(lib);

    const mod = b.addModule("lmdb-zig-mod", .{ .root_source_file = b.path("lmdb.zig") });
-    mod.addIncludePath(dep_lmdb_c.path(""));
+    mod.addIncludePath(.{.cwd_relative = b.pathJoin(&.{b.install_path, "include"})});
+    mod.linkLibrary(lib);

Work around

You can explicitly specify the include path for lmdb-zig-mod to build successfully.

pub fn build(b: *std.Build) void {
    // (snip)
-    exe.root_module.addImport("lmdb", lmdb.module("lmdb-zig-mod"));    
+   const mod_lmdb = lmdb_zig.module("lmdb-zig-mod");
+   mod_lmdb.addIncludePath(findLmdbIncludePath(lmdb_zig) orelse @panic("Not found the imdb include path."));
+   exe.root_module.addImport("lmdb", mod_lmdb);
    exe.linkLibrary(lmdb_zig.artifact("lmdb-zig"));

    b.installArtifact(exe);
    // (snip)
}

fn findLmdbIncludePath(dep_lmdb: *std.Build.Dependency) ?std.Build.LazyPath {
    for (dep_lmdb.artifact("lmdb-zig").root_module.link_objects.items) |obj| {
        if (std.meta.activeTag(obj) == .c_source_files) {
            return obj.c_source_files.root;
        }
    }

    return null;
}   

If lmdb-zig-mod is appropriately specified include path, your code will be following:

    exe.root_module.addImport("lmdb", lmdb.module("lmdb-zig-mod"));
-    exe.linkLibrary(lmdb.artifact("lmdb-zig")); // remove here
    b.installArtifact(exe);
1 Like

Thanks a lot, it works perfect. 0.13 way of using c libraries with wrappers.