Hi again
I need to link a program against a few libraries:
With zig 0.10 I did it like this:
const exe = b.addExecutable("xjiss", "src/main.zig");
exe.single_threaded = true;
exe.linkLibC();
exe.linkSystemLibrary("X11");
exe.linkSystemLibrary("asound");
How do I do this with zig 0.11?
ExecutableOptions
structure contains boolean link_libc
field, ok.
But how to link the other two, X11
and asound
?
I guess one has something to do with linkage
field, right?
Linking system libraries and libc should still work like in 0.10.
What error do you get when you try it?
Actually, I did not because I thought something has changed.
Ok, I’ll try.
JPL
August 4, 2023, 6:16pm
5
if it can help you i did it like this
exe.linkLibC();
exe.addObjectFile(.{.cwd_relative = "/usr/lib/libpcre2-posix.so"});
Yes, that’s right!
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "xjiss",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
.single_threaded = true,
.link_libc = true,
});
exe.linkSystemLibrary("X11");
exe.linkSystemLibrary("asound");
b.installArtifact(exe);
}
works.
Thanks.