How do I determine my native target triple?

My game builds with “zig build” on my Ubuntu laptop, but when I try and compile it on the same laptop with “zig build -Dtarget=x86_64-linux-gnu” I get a missing dependency build error… it seems I don’t know my own target triple!

How do I determine what my native target triple is for a regular “zig build”?

what is the exact error?

I don’t see how it’s relevant, but:

error: error: unable to find dynamic system library ‘X11’ using strategy ‘paths_first’. searched paths: none

To get your build triplet your can print b.graph.host.result.abi | os.tag | cpu.arch

-Dtarget=x68_64-linux-gnu implies cross compilation (if it’s your native target, it’s “for a computer that’s not yours” and not “for a computer with a different architecture”), so you need to manually specify that you want to link libc in the build script.

const mod = b.addModule("something", .{
 .root_source_file = b.path("src/root.zig"),
 .optimize = optimize,
 .target = target,
 .link_libc = true,
});

Your target isn’t the problem, Ubuntu doesn’t have x11, it uses wayland by default.

I think you can switch to x11, but you’d have to install all the x11 stuff.

There is also xwayland to allow x11 apps to run in wayland.

You can also just support wayland in your program, I imagine you’re likely using a library that already supports it.

Ah, right. I guess I’m even more confused now then.

Inserting:

    const dprint = std.debug.print;
    const abi = b.graph.host.result.abi;
    const os = b.graph.host.result.os.tag;
    const arch = b.graph.host.result.cpu.arch;
    dprint("BUILD DEBUG: {} {} {}\n", .{abi, os, arch});

into my build script gives:

BUILD DEBUG: .gnu .linux .x86_64

so why would a standard zig build compile, but manually specifying x86_64-linux-gnu in the target fail?

Edit: I should note that my laptop is currently using wayland; that’s my result of echo $XDG_SESSION_TYPE

so why would a standard zig build compile, but manually specifying x86_64-linux-gnu in the target fail?

Because zig build by default looks for libraries in the standard places they can be found on your system (your path, /lib, /usr/lib, etc), while zig build -Dtarget=x86_64-linux-gnu does not.

That’s what I meant with “implies cross compiling”.

If you’re doing a native/default build, the build system assumes whatever libraries it can find on your system are the ones the program needs, because the software will be running on this computer.

If you’re passing a target, the build system can no longer assume that, so you need to specify where it is allowed to look for libraries. That might be different on the computer that needs to run the software, even if it’s for the same target.

That’s the paths searched: none part of the error message you’re getting.

Why are you trying to build with -Dtarget=...?

1 Like

Ah, sweet that makes everything clearer.

I was interesting in “gross compiling” because I’m currently interesting in cross-compiling my game. I know it should be possible (and that it’s likely simple). I guess based on your response a large part of it will be hunting down the system dependencies my game relies on, and linking them explicitly.

Another way to get your native target triple:

$ zig env | grep target
2 Likes

Something like that, yes. Good luck on the hunt! :slight_smile:

Use zig build-exe --show-builtin to see what is going on for your default debug build, or use it with specific options to see how that changes the builtins:

1 Like