Alpine Linux 的 libc 使用的是 musl ,Clang 是作为前端编译器,实际链接的时候是使用 musl 的库。
安装 Clang 和 lld:
$ apk add clang lld
编译 C 源码:
$ clang -fuse-ld=lld main.c
$ ldd a.out
/lib/ld-musl-aarch64.so.1 (0xfff561cb0000)
libc.musl-aarch64.so.1 => /lib/ld-musl-aarch64.so.1 (0xfff561cb0000)
可以看到依赖很干净,不像 glibc 那样。
如果想要静态链接,加上 -static
参数就行了:
$ clang -fuse-ld=lld -static main.c
$ ldd a.out
/lib/ld-musl-aarch64.so.1: a.out: Not a valid dynamic program