i’m trying to build a static executable. when i enable .linkage = .static
i get this error:
error: error: using shared libraries requires dynamic linking
the dependent modules are both static libraries, and the two system libraries sodium/oprf are both available in /usr/lib/lib<name>.a
, i even tried using linkSystemLibrary2()
as commented out in my build.zig
below, but that doesn’t help either. if i uncomment the .linkage = .static
everything builds fine, but the result is dynamically linked against muslc.
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse true;
const relro = b.option(bool, "relro", "Force all relocations to be read-only after processing") orelse true;
const toml_package = b.dependency("zig-toml", .{
.target = target,
.optimize = optimize,
});
const toml_module = toml_package.module("toml");
const bearssl_package = b.dependency("zig-bearssl", .{
.target = target,
.optimize = optimize,
});
const bearssl_module = bearssl_package.module("bearssl");
const exe = b.addExecutable(.{
.name = "server",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.linkage = .static,
});
exe.pie = pie;
exe.link_z_relro = relro;
exe.root_module.addImport("toml", toml_module);
exe.root_module.addImport("bearssl", bearssl_module);
exe.linkLibrary(bearssl_package.artifact("zig-bearssl"));
//exe.linkSystemLibrary2("oprf", .{.preferred_link_mode = .static});
//exe.linkSystemLibrary2("sodium", .{.preferred_link_mode = .static});
exe.linkSystemLibrary("oprf");
exe.linkSystemLibrary("sodium");
exe.addSystemIncludePath(.{ .cwd_relative = "/usr/include/oprf/noiseXK/" });
exe.addSystemIncludePath(.{ .cwd_relative = "/usr/include/oprf/noiseXK/karmel" });
exe.addSystemIncludePath(.{ .cwd_relative = "/usr/include/oprf/noiseXK/karmel/minimal" });
exe.addIncludePath(b.path("."));
exe.addCSourceFile(.{ .file = b.path("src/workaround.c"), .flags = &[_][]const u8{"-Wall"} });
//exe.linkLibC();
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);
}