如下, --no-as-needed
会把所有指定的库标记为 NEEDED, 即使没用到; --as-needed
会忽略没用到的库;
$ cc -Wl,--no-as-needed xx.c -ldl -lz -lm -l pthread
$ ldd a.out
linux-vdso.so.1 (0x00007fffc03d1000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fad234ae000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fad23491000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fad2334d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fad2332b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fad23156000)
/lib64/ld-linux-x86-64.so.2 (0x00007fad234c5000)
$ cc -Wl,--as-needed xx.c -ldl -lz -lm -l pthread
$ ldd a.out
linux-vdso.so.1 (0x00007ffeb7df8000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f88d1ec3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f88d20a9000)
$
标签:依赖,x86,lib,gnu,去除,编译,64,so.6,linux
From: https://www.cnblogs.com/sinpo828/p/17483641.html