LD == 命令行选项 ---------- .. versionadded:: @2019-02-20 创建 gcc 使用 `-Wl,` 前缀,例如 `-Wl,--as-needed`\。 * --as-needed 允许链接器忽略不需要的库。其他两个参数: * --no-undefined * --no-allow-shlib-undefined 参考 `Unresolved symbols in shared libraries `_ 和 `Project:Quality Assurance/As-needed `_\。 环境变量 -------- * LD_DEBUG .. versionadded:: @2011-03-09 创建 If LD_DEBUG is set, the linker will dump many useful debug information. See help below: :: $ LD_DEBUG=help id Valid options for the LD_DEBUG environment variable are: libs display library search paths reloc display relocation processing files display progress for input file symbols display symbol table processing bindings display information about symbol binding versions display version dependencies scopes display scope information all all previous options combined statistics display relocation statistics unused determined unused DSOs help display this help message and exit To direct the debugging output into a file instead of standard output a filename can be specified using the LD_DEBUG_OUTPUT environment variable. See following example for a common error `cannot open shared object file: No such file or directory`: :: $ vim vim: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory $ LD_DEBUG=libs vim 23579: find library=libSM.so.6 [0]; searching ... 23579: find library=libgcc_s.so.1 [0]; searching 23579: search cache=/etc/ld.so.cache 23579: trying file=/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/libgcc_s.so.1 23579: search path=/lib64/tls/x86_64/x86_64:/lib64/tls/x86_64:/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64/x86_64:/lib64/x86_64:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64/x86_64:/usr/lib64/tls/x86_64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64/x86_64:/usr/lib64/x86_64:/usr/lib64/x86_64:/usr/lib64 (system search path) 23579: trying file=/lib64/tls/x86_64/x86_64/libgcc_s.so.1 23579: trying file=/lib64/tls/x86_64/libgcc_s.so.1 23579: trying file=/lib64/tls/x86_64/libgcc_s.so.1 23579: trying file=/lib64/tls/libgcc_s.so.1 23579: trying file=/lib64/x86_64/x86_64/libgcc_s.so.1 23579: trying file=/lib64/x86_64/libgcc_s.so.1 23579: trying file=/lib64/x86_64/libgcc_s.so.1 23579: trying file=/lib64/libgcc_s.so.1 23579: trying file=/usr/lib64/tls/x86_64/x86_64/libgcc_s.so.1 23579: trying file=/usr/lib64/tls/x86_64/libgcc_s.so.1 23579: trying file=/usr/lib64/tls/x86_64/libgcc_s.so.1 23579: trying file=/usr/lib64/tls/libgcc_s.so.1 23579: trying file=/usr/lib64/x86_64/x86_64/libgcc_s.so.1 23579: trying file=/usr/lib64/x86_64/libgcc_s.so.1 23579: trying file=/usr/lib64/x86_64/libgcc_s.so.1 23579: trying file=/usr/lib64/libgcc_s.so.1 23579: vim: error while loading shared libraries: libgcc_s.so.1: cannot open shared object file: No such file or directory