static linking

cc -static file_name.c command is not working, it's showing an error

ld: library not found for -lcrt0.o

clang: error: linker command failed with exit code 1 (use -v to see invocation)

how to solve this error?

Accepted Reply

What are you trying do with static linking?

Apple’s tools support static libraries but they do not support statically linking an entire executable [1]. All programs must link to the System framework (aka libSystem) in order to access the kernel. Apple only guarantees binary compatible at that layer. A statically linked executable would have to make system calls directly, and we do not guarantee binary compatible there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] The only statically linked executable you’ll find in common use is dyld, the dynamic linker. That has to be statically linked, for obvious reasons. However, that ships with the system and thus doesn’t have to worry about binary compatibility.

Replies

What are you trying do with static linking?

Apple’s tools support static libraries but they do not support statically linking an entire executable [1]. All programs must link to the System framework (aka libSystem) in order to access the kernel. Apple only guarantees binary compatible at that layer. A statically linked executable would have to make system calls directly, and we do not guarantee binary compatible there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] The only statically linked executable you’ll find in common use is dyld, the dynamic linker. That has to be statically linked, for obvious reasons. However, that ships with the system and thus doesn’t have to worry about binary compatibility.