Hi there! I’m trying to use the Zig build system and toolchain to replace my embedded/GameCube C++ project’s build tooling entirely. I’m nearly there, but I need to ultimately build a relocatable ELF library, so that it may be converted to GameCube’s native object format by another tool.
Note the -r - I can’t seem to find a way to link a relocatable ELF via the build system APIs, for one. I wouldn’t mind needing to shell out to zig ld.lld in a run step explicitly if required, but I’m also not sure how to determine the path of the zig executable to use e.g. the one used to invoke zig build.
It sounds like you’re looking for a Compile step which emits an object file (i.e. a relocatable) rather than an executable or library. Take a look at std.Build.addObject, it should do what you need.
(It’s recommended to avoid using zig ld.lld directly fwiw—that subcommand is an implementation detail and could disappear at any time!)
It’s an accurate description (it marks the symbol as initially undefined which means the linker is required to find a definition for the link to succeed—this is important because it means the linker will include objects from static libraries if the objects define those symbols), but I agree a confusing one. I think linker CLI is something Zig can easily improve on compared to traditional linker implementations. A better name for this flag would probably be something like --need-definition for instance.