#Statically linking on macOS

1 messages · Page 1 of 1 (latest)

lethal bluff
#

Is it possible to produce a fully statically linked binary on macOS?
I've tried:

zig build-exe -O ReleaseSmall main.zig -dead_strip -dead_strip_dylibs -static --gc-sections -fomit-frame-pointer

That gave me

error: unable to create compilation: UnableToStaticLink

sterile sluice
#

Probably not, see apple documentation

lament slate
#

in theory yes, you can, but you will need to provide the system calls yourself, which are not stable so they change from version to version

sterile sluice
#

There is no guarantee they are there or not

lethal bluff
#

I see. Is that the reason for the larger binary sizes on macOS? I get 52k on macOS, 9k on Linux, 5k on Windows

lament slate
#

clang is able to produce 16k executables

#

for aarch64 macos

lethal bluff
#

when using write or without?

#

probably doesn't matter because we need the syscall for exit either way I guess

lament slate
#

just an Zig empty main function

lethal bluff
#

yeah, I'm getting 52k with an empty main function

lament slate
#

or int main() { return 0; }

#

the binary size should be lower

#

maybe it's related to the Zig linker since Zig uses its own by default when targetting macos

sterile sluice
#

crossplatform targetting iirc

lethal bluff
lament slate
#

there's a use_lld option afaik

lethal bluff
#

zig build-exe --help | rg use_lld
didn't find anything

#

oh

lament slate
#

i am talking about build.zig

#

i dont use the command line at all

lethal bluff
#

ah, let me check

#

it does exist 🙂

#

but it's not supported:

zig build-exe svclog ReleaseSmall native: error: error: LLD requested with Mach-O object format. Only the self-hosted linker is supported for this target.

#

Anyway, thanks for the help

lament slate
#

oh

#

no problem