Skip to content

linker identification issues when using zig as C compiler for meson based projects #17480

@bo-nemk

Description

@bo-nemk

Zig Version

0.12.0-dev.414+461036069

Steps to Reproduce and Observed Behavior

In my understanding, meson build system has limited support for linkers. It seems to check what linker you are using with:

CC -Wl,--version

If it cannot find a supported linker, it will not build. As of now, it does not support the zig linker:

$ zig cc -Wl,--version
zig ld 0.12.0-dev.414+461036069

This is problematic, as meson can't handle this.

A typical workaround would be as follows.
When running this with clang (the zig compiler backend as I understand it), I obtain:

$ clang -Wl,--version
GNU ld (GNU Binutils for Debian) 2.40

Apparently, it's using ld. If hypothetically this is undesirable, this can be changed by specifying the linker directly:

$ clang -fuse-ld=lld -Wl,--version
Debian LLD 14.0.6 (compatible with GNU linkers) 

This trick doesn't work with zig, however:

$ zig cc -fuse-ld=lld -Wl,--version
zig ld 0.12.0-dev.414+461036069

Expected Behavior

For interop with meson, it would be nice if zig acted as clang does, i.e.:

$ zig cc -fuse-ld=lld -Wl,--version
Debian LLD 14.0.6 (compatible with GNU linkers) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorlinking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions