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”?
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.
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.
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.
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: