Related Ticket
#31559
Zig Version
0.16.0
Summary
Running 'zig build -Dtarget=...adds a-target=...` switch to translate-c which always fails reporting unable to find libraries. However, merely running zig build works fine.
In my case I am translating header files only; it's a judgement call whether it needs a specific target. I can work probably around this by using some default target.
I'm loving Zig and it has great potential for use in kernel by-pass NIC/HPC work (RDMA, RoCE, ibverbs, dpdk etc.). So it'd be cool to get this tech'd out.
Steps to Reproduce and Observed Behavior
(1) After running zig init make a single line header file on any C library. Here I use NUMA (apt install numa):
// file: numa.h
#include <numa.h>
(2) In build.zig provide:
const numa_c = b.addTranslateC(.{
.root_source_file = b.path("./numa.h"),
.target = target,
.optimize = optimize,
});
numa_c.linkSystemLibrary("numa", .{});
(3) Running zig build suceeds.
(4) Running zig build -Dtarget=x86_64-linux-gnu fails in translate-c.
error: error: unable to find dynamic|static system library 'numa' using strategy 'paths_first'. searched paths: none
The only difference between (3) and (4) is adding -Dtarget to zig build telescopes into translate-c
zig translate-c ... -target x86_64-linux-gnu ... numa.h --listen=-
Simply removing the -target switch on translate-c works.
(5) I tried to work around this problem by manually adding known/correct paths.
const includeDir = std.Build.LazyPath{.cwd_relative = "/usr/include"};
const libDir = std.Build.LazyPath{.cwd_relative = "/usr/lib/x86_64-linux-gnu"};
const numa_c = b.addTranslateC(.{
.root_source_file = b.path("./numa.h"),
.target = target,
.optimize = optimize,
});
numa_c.addIncludePath(includeDir);
numa_c.addFrameworkPath(libDir);
numa_c.addSystemFrameworkPath(libDir);
numa_c.linkSystemLibrary("numa", .{});
These calls modifies step fields:
include_dirs: std.array_list.Managed(std.Build.Module.IncludeDir),
system_libs: std.ArrayList(std.Build.Module.SystemLib),
These calls do indeed add additional arguments to the translate-c invocation, but still runs into the same ultimate error.
### Related Ticket
https://codeberg.org/ziglang/zig/issues/31559
### Zig Version
0.16.0
### Summary
Running 'zig build -Dtarget=...` adds a `-target=...` switch to translate-c which always fails reporting unable to find libraries. However, merely running zig build works fine.
In my case I am translating header files only; it's a judgement call whether it **needs** a specific target. I can work probably around this by using some default target.
I'm loving Zig and it has great potential for use in kernel by-pass NIC/HPC work (RDMA, RoCE, ibverbs, dpdk etc.). So it'd be cool to get this tech'd out.
### Steps to Reproduce and Observed Behavior
(1) After running zig init make a single line header file on any C library. Here I use NUMA (apt install numa):
// file: numa.h
#include <numa.h>
(2) In build.zig provide:
const numa_c = b.addTranslateC(.{
.root_source_file = b.path("./numa.h"),
.target = target,
.optimize = optimize,
});
numa_c.linkSystemLibrary("numa", .{});
(3) Running zig build suceeds.
(4) Running zig build -Dtarget=x86_64-linux-gnu **fails in translate-c**.
error: error: unable to find dynamic|static system library 'numa' using strategy 'paths_first'. searched paths: none
The only difference between (3) and (4) is adding -Dtarget to zig build telescopes into translate-c
zig translate-c ... -target x86_64-linux-gnu ... numa.h --listen=-
Simply removing the -target switch on translate-c works.
(5) I tried to work around this problem by manually adding known/correct paths.
const includeDir = std.Build.LazyPath{.cwd_relative = "/usr/include"};
const libDir = std.Build.LazyPath{.cwd_relative = "/usr/lib/x86_64-linux-gnu"};
const numa_c = b.addTranslateC(.{
.root_source_file = b.path("./numa.h"),
.target = target,
.optimize = optimize,
});
numa_c.addIncludePath(includeDir);
numa_c.addFrameworkPath(libDir);
numa_c.addSystemFrameworkPath(libDir);
numa_c.linkSystemLibrary("numa", .{});
These calls modifies step fields:
include_dirs: std.array_list.Managed(std.Build.Module.IncludeDir),
system_libs: std.ArrayList(std.Build.Module.SystemLib),
These calls do indeed add additional arguments to the translate-c invocation, but still runs into the same ultimate error.