# std.Build: add \`addLibrary\` function \(\#22554\) · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/941677e08318c2baaabc9d0fc87892d1b63487ae)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 941677e08318c2baaabc9d0fc87892d1b63487ae

Requested commit: 941677e08318c2baaabc9d0fc87892d1b63487ae

Commit: 941677e08318c2baaabc9d0fc87892d1b63487ae

Tree: 3a6682be6f5063e6d7a27bd90d50a9cf729d5937

Author: BratishkaErik

Committer: GitHub

## Message

````
std.Build: add `addLibrary` function (#22554)

Acts as a replacement for `addSharedLibrary` and `addStaticLibrary`, but
linking mode can be changed more easily in build.zig, for example:

In library:
```zig
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for a foo_bar library") orelse .static; // or other default

const lib = b.addLibrary(.{
    .linkage = linkage,
    .name = "foo_bar",
    .root_module = mod,
});
```

In consumer:
```zig
const dep_foo_bar = b.dependency("foo_bar", .{
    .target = target,
    .optimize = optimize,
    .linkage = .static // or dynamic
});

mod.linkLibrary(dep_foor_bar.artifact("foo_bar"));
```

It also matches nicely with `linkLibrary` name.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
````

## Parents

- [28a259d4a34e544090a76863802e600a4e01fcc2](https://git.cafe/gitcafe/zig/commit/28a259d4a34e544090a76863802e600a4e01fcc2?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/941677e08318c2baaabc9d0fc87892d1b63487ae?format=markdown)
