Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is factually incorrect. While some operating systems use libc as the syscall ABI, this is not the case for Windows or Linux. On those systems, by default, Zig programs do not link libc; they make DLL calls or syscalls directly.

The project in question, however, does seem to link libc in the build script for no reason, as well as create a static library for no reason (it doesn't export any functions). As Loris pointed out to me today, this is likely caused by the `zig init` template highlighting static linking rather than modules, which is unfortunate since modules are the preferred way for Zig code to import other Zig code. We'll be adjusting that accordingly.



i do link libc because i just copied build.zig from another project i made zig-dotenv and forgot to remove the line

seems like i created a bit of a fuss there, my bad


You don't have anything to apologize for, you just are partway through your journey of learning about static libraries, dynamic libraries, and compilation units :-)


> On those systems, by default, Zig programs do not link libc; they make DLL calls or syscalls directly.

Well, that makes me think a lot less of Zig. Bypassing libc makes programs less cooperative members of the broader ecosystem. There's value in libc being able to act as a userspace intermediary between programs and the kernel. (That's why Windows doesn't provide a way to make direct system calls: you're going to go through kernel32/user32/etc. -> ntdll.dll and _then_ the kernel.)

Go bypassing libc causes all sorts of annoying havoc, e.g. fakeroot stuff not working. This is not behavior to be encouraged.

And for what benefit? Being able to say you're libc-free, as if that were a feature not a bug? You don't even have split stacks. Is it just that libc has "c" in the name and you want to make sure nobody thinks you're C? libc being called lib-c is an historical artifact. It's not even about C itself. It's more like Windows ntdll.

Bypassing libc is fundamentally selfish behavior. It breaks a longstanding ecosystem coordination mechanism for zero actual benefit.

But hey, I can still use "zig cc" as a convenient cross-compiler when I'm writing in a better-behaved language -- so thanks, I guess.


On windows you make system calls through the DLLs because the system calls can change on you. On linux you're pretty much guaranteed that the API to the kernel will not change. It will get extended, but the semantics of old calls will not change).


So? That you can do something doesn't mean you should. Bypassing libc breaks workflows. Zig and Go aren't worse off on non-Linux platforms because those platforms enforce talking to the kernel through a library. Nobody, in either the Zig or the Go worlds, has justified bypassing libc in terms of concrete and specific user benefit.


If you need libc, just link libc? It's bizarre to me that you think less of Zig for giving you the choice.


libc's been poisoning software long enough. Glad it's optional in Zig on platforms that provide stable system ABI.


"[P]oisoning"? Do you have a technical objection, or do you just not like the letter "c"?


libc, starting with errno, continuing with fopen/printf/str* functions, locales, etc is a pile of quick hacks; set of useful abstractions at the time, no doubt! But that time is long gone, for decade(s) it is nothing but a drag.


libc carries lots of global state and implicit ABI that complicates software stacks. While I don't like dynamic libraries in general, dynamic libraries wouldn't be such a mess as they are if libc did not exist. I dream of day we can actually do GPU rendering on linux without libc, and have actual static binaries for graphical apps that work everywhere.


That global state is the coordination problem it's solving. Who owns the thread list? The current process wide setreuid identity? The loaded library list? Debug info registrations? Shared dynamic memory allocations? TLS slots? Someone has to, and that someone is libc. Avoiding it because it has state is to be confused about the whole concept of an OS.

Yeah, it's mixed up with the same library that provides sscanf and strcat. So what? You don't have to call them.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: