Reputation: 4163
I am reading this reddit reply and I came across this:
To answer your question, Zig has a pretty unique and intimate relationship with libc. Zig can use libc (some Operating systems like MacOS and BSD require going through libc). Zig can also work without libc, on Linux Zig will use the stable syscall interface and on Windows Zig can use platform Dlls like ntdll and kernel32 directly.
Zig also provides all the header files and link libraries to link against external libc libraries like GLIBC, the MacOS Libc, etc. Zig can even link against older versions of GLIBC, something GCC doesnt even support. Zig also ships with MinGW which enables you to build C applications on Windows without Visual Studio. It doesn't always work but I'm currently working on an alternative to MinGW, ZIGLIBC, that could make this alot better in the future. For Linux Zig also ships with Musl which includes a full libc implementation. This makes it possible to build static applications for any target including freestanding ones that may not have GLIBC installed system wide
Based on the statement above, I have the following questions:
Zig can use libc (some Operating systems like MacOS and BSD require going through libc)
How can I confirm if I am on macOS then libc is being used?
Zig also provides all the header files and link libraries to link against external libc libraries like GLIBC, the MacOS Libc, etc.
I have Zig installed, is it possible for me to see these header files? How can I see them?
Zig can even link against older versions of GLIBC, something GCC doesnt even support
What would be the process of specifying the version of GLIBC zig should link with? So that I can confirm the statement "Zig can even link against older versions of GLIBC"
Zig also ships with MinGW which enables you to build C applications on Windows without Visual Studio
Similar to question 3, how would I set up Zig to build against MinGW, so that I can confirm the statement above.
For Linux Zig also ships with Musl which includes a full libc implementation. This makes it possible to build static applications for any target including freestanding ones that may not have GLIBC installed system wide
If I am on a Mac, can I instruct Zig to use Musl instead? if so how do I?
I think the core of my question revolves around Zig relationship with libraries it needs to link with while compiling and how to configure this.
Upvotes: 1
Views: 531
Reputation: 3577
otool -L zig-out/bin/mybinary
will say if a binary links libraries and which ones. Any binary built for mac by zig will link libSystem which includes libc. Also, @import("builtin").link_libc
will always be true on mac.zig env
will print "lib_dir": "..."
. This directory contains all the header files zig ships with. eg: lib/libc/musl/include/stdio.h
zig targets
. Run zig targets | less
and search for glibc (type /glibc
then enter) to see all the versions zig knows about. To build for an old glibc version, specify it in the target triple: zig build -Dtarget=x86_64-linux-gnu.2.16.0
(as long as exe.linkLibC()
is in build.zig), or with zig build-exe
: zig build-exe myprogram.zig -target x86_64-linux-gnu.2.16.0 -lc
. The first working version on a zig program seems to be 2.16.0
x86_64-windows-gnu
x86_64-linux-musl
), but you cannot use musl on mac for a mac build. The libc built into libSystem is macOS's syscall abi. Syscalls are allowed to change between macOS versions, but libSystem stays stable. Making a static binary that links musl on mac doesn't make sense for this reason.Upvotes: 0