获取gcc链接详细信息

gcc在链接过程中,会链接很多库,包括动态库或者静态库。而这些库,包含了若干的.o文件,而在链接的过程中,不是每一个.o文件,都会链接到最终生成的文件中的。那么如何知道,库中的哪些.o文件,链接到最终生成的文件中呢?

通过查找资料,找到了gcc的链接选项,-Xlinker –verbose,就可以得到链接,所使用的库中的.o文件。

比如如下c文件:

#include <stdio.h>
#include <math.h>
int main() {
int k = -0;
unsigned j;
j = fabs(k);
printf("j=%x\n", j);
return 0;
}

一、动态库链接

使用如下命令编译:

gcc main.c -Xlinker --verbose

以下是输出信息:

attempt to open /usr/lib/../lib64/crt1.o succeeded

/usr/lib/../lib64/crt1.o

attempt to open /usr/lib/../lib64/crti.o succeeded

/usr/lib/../lib64/crti.o

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/crtbegin.o succeeded

/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/crtbegin.o

attempt to open /tmp/ccSBhfuZ.o succeeded

/tmp/ccSBhfuZ.o

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.so failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.a succeeded

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_s.so failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_s.a failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so succeeded

opened script file /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so

opened script file /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so

attempt to open libgcc_s.so.1 failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_s.so.1 failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so.1 succeeded

libgcc_s.so.1 (/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so.1)

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.so failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.a succeeded

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libc.so failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libc.a failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libc.so failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libc.a failed

attempt to open /lib/../lib64/libc.so failed

attempt to open /lib/../lib64/libc.a failed

attempt to open /usr/lib/../lib64/libc.so succeeded

opened script file /usr/lib/../lib64/libc.so

opened script file /usr/lib/../lib64/libc.so

attempt to open /lib64/libc.so.6 succeeded

/lib64/libc.so.6

attempt to open /usr/lib64/libc_nonshared.a succeeded

(/usr/lib64/libc_nonshared.a)elf-init.oS

attempt to open /lib64/ld-linux-x86-64.so.2 succeeded

/lib64/ld-linux-x86-64.so.2

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.so failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.a succeeded

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_s.so failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_s.a failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so succeeded

opened script file /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so

opened script file /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so

attempt to open libgcc_s.so.1 failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_s.so.1 failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so.1 succeeded

libgcc_s.so.1 (/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libgcc_s.so.1)

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.so failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.a succeeded

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/crtend.o succeeded

/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/crtend.o

attempt to open /usr/lib/../lib64/crtn.o succeeded

/usr/lib/../lib64/crtn.o

ld-linux-x86-64.so.2 needed by /lib64/libc.so.6

found ld-linux-x86-64.so.2 at /lib64/ld-linux-x86-64.so.2

从输出结果可以看到,链接动态库过程的详细信息,包括:

  • 链接哪些库

  • 链接库的位置

  • 链接库是否成功

二、静态库链接

如果使用如下命令:

gcc main.c -static -Xlinker --verbose

以下是输出信息:

attempt to open /usr/lib/../lib64/crt1.o succeeded

/usr/lib/../lib64/crt1.o

attempt to open /usr/lib/../lib64/crti.o succeeded

/usr/lib/../lib64/crti.o

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/crtbeginT.o succeeded

/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/crtbeginT.o

attempt to open /tmp/ccYjETs6.o succeeded

/tmp/ccYjETs6.o

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc.a succeeded

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_eh.a succeeded

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libc.a failed

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/../../../../lib64/libc.a failed

attempt to open /lib/../lib64/libc.a failed

attempt to open /usr/lib/../lib64/libc.a succeeded

(/usr/lib/../lib64/libc.a)libc-start.o

(/usr/lib/../lib64/libc.a)check_fds.o

(/usr/lib/../lib64/libc.a)libc-tls.o

(/usr/lib/../lib64/libc.a)elf-init.o

(/usr/lib/../lib64/libc.a)errno.o

(/usr/lib/../lib64/libc.a)bsd-_setjmp.o

(/usr/lib/../lib64/libc.a)exit.o

(/usr/lib/../lib64/libc.a)cxa_atexit.o

(/usr/lib/../lib64/libc.a)printf.o

(/usr/lib/../lib64/libc.a)libc_fatal.o

(/usr/lib/../lib64/libc.a)stdio.o

(/usr/lib/../lib64/libc.a)malloc.o

(/usr/lib/../lib64/libc.a)morecore.o

(/usr/lib/../lib64/libc.a)strlen.o

(/usr/lib/../lib64/libc.a)memcmp.o

(/usr/lib/../lib64/libc.a)memset.o

(/usr/lib/../lib64/libc.a)mempcpy.o

(/usr/lib/../lib64/libc.a)memcpy.o

(/usr/lib/../lib64/libc.a)strchrnul.o

(/usr/lib/../lib64/libc.a)memcmp-sse4.o

(/usr/lib/../lib64/libc.a)memset-x86-64.o

(/usr/lib/../lib64/libc.a)cacheinfo.o

(/usr/lib/../lib64/libc.a)_exit.o

(/usr/lib/../lib64/libc.a)environ.o

(/usr/lib/../lib64/libc.a)exit-thread.o

(/usr/lib/../lib64/libc.a)fxstat.o

(/usr/lib/../lib64/libc.a)open.o

(/usr/lib/../lib64/libc.a)read.o

(/usr/lib/../lib64/libc.a)write.o

(/usr/lib/../lib64/libc.a)fcntl.o

(/usr/lib/../lib64/libc.a)sbrk.o

(/usr/lib/../lib64/libc.a)getpagesize.o

(/usr/lib/../lib64/libc.a)syslog.o

(/usr/lib/../lib64/libc.a)mmap.o

(/usr/lib/../lib64/libc.a)munmap.o

(/usr/lib/../lib64/libc.a)mprotect.o

(/usr/lib/../lib64/libc.a)madvise.o

(/usr/lib/../lib64/libc.a)getsysstats.o

(/usr/lib/../lib64/libc.a)init-misc.o

(/usr/lib/../lib64/libc.a)mremap.o

(/usr/lib/../lib64/libc.a)connect.o

(/usr/lib/../lib64/libc.a)send.o

(/usr/lib/../lib64/libc.a)socket.o

(/usr/lib/../lib64/libc.a)have_sock_cloexec.o

(/usr/lib/../lib64/libc.a)alloca_cutoff.o

(/usr/lib/../lib64/libc.a)libc-lowlevellock.o

(/usr/lib/../lib64/libc.a)libc-cancellation.o

(/usr/lib/../lib64/libc.a)register-atfork.o

(/usr/lib/../lib64/libc.a)libc_multiple_threads.o

(/usr/lib/../lib64/libc.a)backtrace.o

(/usr/lib/../lib64/libc.a)backtracesymsfd.o

(/usr/lib/../lib64/libc.a)vfprintf_chk.o

(/usr/lib/../lib64/libc.a)dl-support.o

(/usr/lib/../lib64/libc.a)dl-addr.o

(/usr/lib/../lib64/libc.a)enbl-secure.o

(/usr/lib/../lib64/libc.a)dl-sysdep.o

(/usr/lib/../lib64/libc.a)init-first.o

(/usr/lib/../lib64/libc.a)sysdep.o

(/usr/lib/../lib64/libc.a)init-arch.o

(/usr/lib/../lib64/libc.a)lc-ctype.o

(/usr/lib/../lib64/libc.a)xlocale.o

(/usr/lib/../lib64/libc.a)global-locale.o

(/usr/lib/../lib64/libc.a)ctype-info.o

(/usr/lib/../lib64/libc.a)setfpucw.o

(/usr/lib/../lib64/libc.a)fpu_control.o

(/usr/lib/../lib64/libc.a)setjmp.o

(/usr/lib/../lib64/libc.a)sigjmp.o

(/usr/lib/../lib64/libc.a)sigprocmask.o

(/usr/lib/../lib64/libc.a)abort.o

(/usr/lib/../lib64/libc.a)bsearch.o

(/usr/lib/../lib64/libc.a)getenv.o

(/usr/lib/../lib64/libc.a)setenv.o

(/usr/lib/../lib64/libc.a)secure-getenv.o

(/usr/lib/../lib64/libc.a)strtol.o

(/usr/lib/../lib64/libc.a)strtoul.o

(/usr/lib/../lib64/libc.a)strtol_l.o

(/usr/lib/../lib64/libc.a)strtoul_l.o

(/usr/lib/../lib64/libc.a)grouping.o

(/usr/lib/../lib64/libc.a)_itoa.o

(/usr/lib/../lib64/libc.a)itoa-digits.o

(/usr/lib/../lib64/libc.a)itoa-udigits.o

(/usr/lib/../lib64/libc.a)vfprintf.o

(/usr/lib/../lib64/libc.a)printf_fp.o

(/usr/lib/../lib64/libc.a)reg-printf.o

(/usr/lib/../lib64/libc.a)printf_fphex.o

(/usr/lib/../lib64/libc.a)reg-type.o

(/usr/lib/../lib64/libc.a)fprintf.o

(/usr/lib/../lib64/libc.a)dprintf.o

(/usr/lib/../lib64/libc.a)sscanf.o

(/usr/lib/../lib64/libc.a)funlockfile.o

(/usr/lib/../lib64/libc.a)printf-parsemb.o

(/usr/lib/../lib64/libc.a)iofclose.o

(/usr/lib/../lib64/libc.a)iofopen.o

(/usr/lib/../lib64/libc.a)iofputs.o

(/usr/lib/../lib64/libc.a)ioftell.o

(/usr/lib/../lib64/libc.a)iofwrite.o

(/usr/lib/../lib64/libc.a)iopadn.o

(/usr/lib/../lib64/libc.a)ioseekoff.o

(/usr/lib/../lib64/libc.a)iovsscanf.o

(/usr/lib/../lib64/libc.a)iowpadn.o

(/usr/lib/../lib64/libc.a)wgenops.o

(/usr/lib/../lib64/libc.a)wfileops.o

(/usr/lib/../lib64/libc.a)iofwide.o

(/usr/lib/../lib64/libc.a)memstream.o

(/usr/lib/../lib64/libc.a)iovdprintf.o

(/usr/lib/../lib64/libc.a)fcloseall.o

(/usr/lib/../lib64/libc.a)iofgets_u.o

(/usr/lib/../lib64/libc.a)iofputs_u.o

(/usr/lib/../lib64/libc.a)fileops.o

(/usr/lib/../lib64/libc.a)genops.o

(/usr/lib/../lib64/libc.a)stdfiles.o

(/usr/lib/../lib64/libc.a)strops.o

(/usr/lib/../lib64/libc.a)strchr.o

(/usr/lib/../lib64/libc.a)strcmp.o

(/usr/lib/../lib64/libc.a)_strerror.o

(/usr/lib/../lib64/libc.a)strnlen.o

(/usr/lib/../lib64/libc.a)strncmp.o

(/usr/lib/../lib64/libc.a)strrchr.o

(/usr/lib/../lib64/libc.a)memchr.o

(/usr/lib/../lib64/libc.a)memmove.o

(/usr/lib/../lib64/libc.a)wordcopy.o

(/usr/lib/../lib64/libc.a)rawmemchr.o

(/usr/lib/../lib64/libc.a)strcmp-ssse3.o

(/usr/lib/../lib64/libc.a)strend-sse4.o

(/usr/lib/../lib64/libc.a)strstr-c.o

(/usr/lib/../lib64/libc.a)wmemcpy.o

(/usr/lib/../lib64/libc.a)wmemmove.o

(/usr/lib/../lib64/libc.a)wmemset.o

(/usr/lib/../lib64/libc.a)wmempcpy.o

(/usr/lib/../lib64/libc.a)wcrtomb.o

(/usr/lib/../lib64/libc.a)wcsrtombs.o

(/usr/lib/../lib64/libc.a)mbsnrtowcs.o

(/usr/lib/../lib64/libc.a)wcsnlen.o

(/usr/lib/../lib64/libc.a)wcsmbsload.o

(/usr/lib/../lib64/libc.a)localtime.o

(/usr/lib/../lib64/libc.a)time.o

(/usr/lib/../lib64/libc.a)tzset.o

(/usr/lib/../lib64/libc.a)tzfile.o

(/usr/lib/../lib64/libc.a)strftime_l.o

(/usr/lib/../lib64/libc.a)era.o

(/usr/lib/../lib64/libc.a)alt_digit.o

(/usr/lib/../lib64/libc.a)lc-time-cleanup.o

(/usr/lib/../lib64/libc.a)opendir.o

(/usr/lib/../lib64/libc.a)closedir.o

(/usr/lib/../lib64/libc.a)readdir.o

(/usr/lib/../lib64/libc.a)getdents.o

(/usr/lib/../lib64/libc.a)uname.o

(/usr/lib/../lib64/libc.a)fork.o

(/usr/lib/../lib64/libc.a)getpid.o

(/usr/lib/../lib64/libc.a)getuid.o

(/usr/lib/../lib64/libc.a)geteuid.o

(/usr/lib/../lib64/libc.a)getgid.o

(/usr/lib/../lib64/libc.a)getegid.o

(/usr/lib/../lib64/libc.a)sched_yield.o

(/usr/lib/../lib64/libc.a)xstat.o

(/usr/lib/../lib64/libc.a)close.o

(/usr/lib/../lib64/libc.a)access.o

(/usr/lib/../lib64/libc.a)have_o_cloexec.o

(/usr/lib/../lib64/libc.a)brk.o

(/usr/lib/../lib64/libc.a)writev.o

(/usr/lib/../lib64/libc.a)tsearch.o

(/usr/lib/../lib64/libc.a)llseek.o

(/usr/lib/../lib64/libc.a)wctrans.o

(/usr/lib/../lib64/libc.a)towctrans.o

(/usr/lib/../lib64/libc.a)readonly-area.o

(/usr/lib/../lib64/libc.a)dl-load.o

(/usr/lib/../lib64/libc.a)dl-cache.o

(/usr/lib/../lib64/libc.a)dl-lookup.o

(/usr/lib/../lib64/libc.a)dl-object.o

(/usr/lib/../lib64/libc.a)dl-reloc.o

(/usr/lib/../lib64/libc.a)dl-error.o

(/usr/lib/../lib64/libc.a)dl-debug.o

(/usr/lib/../lib64/libc.a)dl-misc.o

(/usr/lib/../lib64/libc.a)dl-tls.o

(/usr/lib/../lib64/libc.a)dl-origin.o

(/usr/lib/../lib64/libc.a)dl-scope.o

(/usr/lib/../lib64/libc.a)dl-execstack.o

(/usr/lib/../lib64/libc.a)dl-trampoline.o

(/usr/lib/../lib64/libc.a)dl-profstub.o

(/usr/lib/../lib64/libc.a)dl-tsd.o

(/usr/lib/../lib64/libc.a)dl-tlsdesc.o

(/usr/lib/../lib64/libc.a)gconv_db.o

(/usr/lib/../lib64/libc.a)gconv_conf.o

(/usr/lib/../lib64/libc.a)gconv_builtin.o

(/usr/lib/../lib64/libc.a)gconv_simple.o

(/usr/lib/../lib64/libc.a)gconv_trans.o

(/usr/lib/../lib64/libc.a)gconv_cache.o

(/usr/lib/../lib64/libc.a)gconv_dl.o

(/usr/lib/../lib64/libc.a)setlocale.o

(/usr/lib/../lib64/libc.a)findlocale.o

(/usr/lib/../lib64/libc.a)loadlocale.o

(/usr/lib/../lib64/libc.a)loadarchive.o

(/usr/lib/../lib64/libc.a)lc-monetary.o

(/usr/lib/../lib64/libc.a)lc-numeric.o

(/usr/lib/../lib64/libc.a)C-ctype.o

(/usr/lib/../lib64/libc.a)C-messages.o

(/usr/lib/../lib64/libc.a)C-monetary.o

(/usr/lib/../lib64/libc.a)C-numeric.o

(/usr/lib/../lib64/libc.a)C-time.o

(/usr/lib/../lib64/libc.a)C-paper.o

(/usr/lib/../lib64/libc.a)C-name.o

(/usr/lib/../lib64/libc.a)C-address.o

(/usr/lib/../lib64/libc.a)C-telephone.o

(/usr/lib/../lib64/libc.a)C-measurement.o

(/usr/lib/../lib64/libc.a)C-identification.o

(/usr/lib/../lib64/libc.a)C-collate.o

(/usr/lib/../lib64/libc.a)SYS_libc.o

(/usr/lib/../lib64/libc.a)C_name.o

(/usr/lib/../lib64/libc.a)dcgettext.o

(/usr/lib/../lib64/libc.a)dcigettext.o

(/usr/lib/../lib64/libc.a)finddomain.o

(/usr/lib/../lib64/libc.a)loadmsgcat.o

(/usr/lib/../lib64/libc.a)localealias.o

(/usr/lib/../lib64/libc.a)l10nflist.o

(/usr/lib/../lib64/libc.a)explodename.o

(/usr/lib/../lib64/libc.a)plural.o

(/usr/lib/../lib64/libc.a)plural-exp.o

(/usr/lib/../lib64/libc.a)hash-string.o

(/usr/lib/../lib64/libc.a)s_isinf.o

(/usr/lib/../lib64/libc.a)s_isnan.o

(/usr/lib/../lib64/libc.a)s_isinfl.o

(/usr/lib/../lib64/libc.a)s_isnanl.o

(/usr/lib/../lib64/libc.a)__longjmp.o

(/usr/lib/../lib64/libc.a)raise.o

(/usr/lib/../lib64/libc.a)sigaction.o

(/usr/lib/../lib64/libc.a)msort.o

(/usr/lib/../lib64/libc.a)cmp.o

(/usr/lib/../lib64/libc.a)divrem.o

(/usr/lib/../lib64/libc.a)lshift.o

(/usr/lib/../lib64/libc.a)rshift.o

(/usr/lib/../lib64/libc.a)mul.o

(/usr/lib/../lib64/libc.a)mul_1.o

(/usr/lib/../lib64/libc.a)mul_n.o

(/usr/lib/../lib64/libc.a)sub_n.o

(/usr/lib/../lib64/libc.a)submul_1.o

(/usr/lib/../lib64/libc.a)dbl2mpn.o

(/usr/lib/../lib64/libc.a)ldbl2mpn.o

(/usr/lib/../lib64/libc.a)fpioconst.o

(/usr/lib/../lib64/libc.a)itowa-digits.o

(/usr/lib/../lib64/libc.a)reg-modifier.o

(/usr/lib/../lib64/libc.a)vfscanf.o

(/usr/lib/../lib64/libc.a)errlist.o

(/usr/lib/../lib64/libc.a)filedoalloc.o

(/usr/lib/../lib64/libc.a)wfiledoalloc.o

(/usr/lib/../lib64/libc.a)iogetdelim.o

(/usr/lib/../lib64/libc.a)iogetline.o

(/usr/lib/../lib64/libc.a)fileno.o

(/usr/lib/../lib64/libc.a)fseek.o

(/usr/lib/../lib64/libc.a)ftello.o

(/usr/lib/../lib64/libc.a)iofread_u.o

(/usr/lib/../lib64/libc.a)strcpy.o

(/usr/lib/../lib64/libc.a)strdup.o

(/usr/lib/../lib64/libc.a)strndup.o

(/usr/lib/../lib64/libc.a)strstr.o

(/usr/lib/../lib64/libc.a)stpcpy.o

(/usr/lib/../lib64/libc.a)strcasecmp_l.o

(/usr/lib/../lib64/libc.a)strsep.o

(/usr/lib/../lib64/libc.a)memmem.o

(/usr/lib/../lib64/libc.a)argz-count.o

(/usr/lib/../lib64/libc.a)argz-ctsep.o

(/usr/lib/../lib64/libc.a)argz-stringify.o

(/usr/lib/../lib64/libc.a)argz-addsep.o

(/usr/lib/../lib64/libc.a)strcasecmp_l-ssse3.o

(/usr/lib/../lib64/libc.a)strcasecmp_l-nonascii.o

(/usr/lib/../lib64/libc.a)wcschr.o

(/usr/lib/../lib64/libc.a)wcslen.o

(/usr/lib/../lib64/libc.a)mbrlen.o

(/usr/lib/../lib64/libc.a)mbrtowc.o

(/usr/lib/../lib64/libc.a)offtime.o

(/usr/lib/../lib64/libc.a)mktime.o

(/usr/lib/../lib64/libc.a)sysconf.o

(/usr/lib/../lib64/libc.a)get_child_max.o

(/usr/lib/../lib64/libc.a)getcwd.o

(/usr/lib/../lib64/libc.a)isatty.o

(/usr/lib/../lib64/libc.a)tcgetattr.o

(/usr/lib/../lib64/libc.a)getrlimit.o

(/usr/lib/../lib64/libc.a)getdtsz.o

(/usr/lib/../lib64/libc.a)getclktck.o

(/usr/lib/../lib64/libc.a)dl-runtime.o

(/usr/lib/../lib64/libc.a)dl-profile.o

(/usr/lib/../lib64/libc.a)dl-libc.o

(/usr/lib/../lib64/libc.a)tlsdesc.o

(/usr/lib/../lib64/libc.a)gconv_open.o

(/usr/lib/../lib64/libc.a)gconv.o

(/usr/lib/../lib64/libc.a)gconv_close.o

(/usr/lib/../lib64/libc.a)localename.o

(/usr/lib/../lib64/libc.a)qsort.o

(/usr/lib/../lib64/libc.a)strtof.o

(/usr/lib/../lib64/libc.a)strtod.o

(/usr/lib/../lib64/libc.a)strtold.o

(/usr/lib/../lib64/libc.a)strtof_l.o

(/usr/lib/../lib64/libc.a)strtod_l.o

(/usr/lib/../lib64/libc.a)strtold_l.o

(/usr/lib/../lib64/libc.a)add_n.o

(/usr/lib/../lib64/libc.a)addmul_1.o

(/usr/lib/../lib64/libc.a)mpn2flt.o

(/usr/lib/../lib64/libc.a)mpn2dbl.o

(/usr/lib/../lib64/libc.a)mpn2ldbl.o

(/usr/lib/../lib64/libc.a)tens_in_limb.o

(/usr/lib/../lib64/libc.a)sdlerror.o

(/usr/lib/../lib64/libc.a)sdladdr.o

(/usr/lib/../lib64/libc.a)sdladdr1.o

(/usr/lib/../lib64/libc.a)sdlinfo.o

(/usr/lib/../lib64/libc.a)sdlmopen.o

(/usr/lib/../lib64/libc.a)strerror.o

(/usr/lib/../lib64/libc.a)strpbrk.o

(/usr/lib/../lib64/libc.a)strncase_l.o

(/usr/lib/../lib64/libc.a)strncase_l-ssse3.o

(/usr/lib/../lib64/libc.a)strncase_l-nonascii.o

(/usr/lib/../lib64/libc.a)profil.o

(/usr/lib/../lib64/libc.a)prof-freq.o

(/usr/lib/../lib64/libc.a)dl-open.o

(/usr/lib/../lib64/libc.a)dl-close.o

(/usr/lib/../lib64/libc.a)asprintf.o

(/usr/lib/../lib64/libc.a)vasprintf.o

(/usr/lib/../lib64/libc.a)sdlopen.o

(/usr/lib/../lib64/libc.a)sdlclose.o

(/usr/lib/../lib64/libc.a)sdlsym.o

(/usr/lib/../lib64/libc.a)sdlvsym.o

(/usr/lib/../lib64/libc.a)setitimer.o

(/usr/lib/../lib64/libc.a)dl-deps.o

(/usr/lib/../lib64/libc.a)dl-init.o

(/usr/lib/../lib64/libc.a)dl-fini.o

(/usr/lib/../lib64/libc.a)dl-version.o

(/usr/lib/../lib64/libc.a)dl-sym.o

(/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_eh.a)unwind-dw2.o

(/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_eh.a)unwind-dw2-fde-dip.o

(/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/libgcc_eh.a)unwind-c.o

(/usr/lib/../lib64/libc.a)dl-iteratephdr.o

attempt to open /usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/crtend.o succeeded

/usr/local/lib/gcc/x86_64-pc-linux-gnu/6.1.0/crtend.o

attempt to open /usr/lib/../lib64/crtn.o succeeded

/usr/lib/../lib64/crtn.o

从输出结果可以看到,链接动态库过程的详细信息,包括:

  • 链接哪些库

  • 链接库的位置

  • 链接库是否成功

  • 链接库中所使用的.o文件

从输出结果看出,即使一个简单的c程序,也会链接库中,非常多的.o文件。

三、总结

可以通过-Xlinker –verbose选项,来获取gcc链接过程中,使用的库以及.o信息。这样会帮忙理解链接过程。

 

此条目发表在linux分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。