$ cat a.c
extern char __libc_single_threaded;
int main(void) {
return __libc_single_threaded;
}
$ clang a.c
$ zig build-exe a.c -lc
ld.lld: error: undefined symbol: __libc_single_threaded
>>> referenced by a.c:3
>>> /home/vexu/.cache/zig/o/00d791557252b46f5ed6668a930dc12a/a.o:(main)
error: LLDReportedFailure
Not sure how this works on other targets but on Arch Linux it means that building stage2 with system LLVM requires this patch:
diff --git a/build.zig b/build.zig
index 5896ab1a8..fb821ccf4 100644
--- a/build.zig
+++ b/build.zig
@@ -550,6 +550,7 @@ fn addCmakeCfgOptionsToExe(
else => |e| return e,
};
exe.linkSystemLibrary("unwind");
+ exe.linkSystemLibrary("c_nonshared");
} else if (exe.target.isFreeBSD()) {
try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes);
exe.linkSystemLibrary("pthread");
Not sure how this works on other targets but on Arch Linux it means that building stage2 with system LLVM requires this patch: