📄 collect2.texi
字号:
@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.@c This is part of the GCC manual.@c For copying conditions, see the file gcc.texi.@node Collect2@chapter @code{collect2}GCC uses a utility called @code{collect2} on nearly all systems to arrangeto call various initialization functions at start time.The program @code{collect2} works by linking the program once andlooking through the linker output file for symbols with particular namesindicating they are constructor functions. If it finds any, itcreates a new temporary @samp{.c} file containing a table of them,compiles it, and links the program a second time including that file.@findex __main@cindex constructors, automatic callsThe actual calls to the constructors are carried out by a subroutinecalled @code{__main}, which is called (automatically) at the beginningof the body of @code{main} (provided @code{main} was compiled with GNUCC)@. Calling @code{__main} is necessary, even when compiling C code, toallow linking C and C++ object code together. (If you use@option{-nostdlib}, you get an unresolved reference to @code{__main},since it's defined in the standard GCC library. Include @option{-lgcc} atthe end of your compiler command line to resolve this reference.)The program @code{collect2} is installed as @code{ld} in the directorywhere the passes of the compiler are installed. When @code{collect2}needs to find the @emph{real} @code{ld}, it tries the following filenames:@itemize @bullet@item@file{real-ld} in the directories listed in the compiler's searchdirectories.@item@file{real-ld} in the directories listed in the environment variable@code{PATH}.@itemThe file specified in the @code{REAL_LD_FILE_NAME} configuration macro,if specified.@item@file{ld} in the compiler's search directories, except that@code{collect2} will not execute itself recursively.@item@file{ld} in @code{PATH}.@end itemize``The compiler's search directories'' means all the directories where@command{gcc} searches for passes of the compiler. This includesdirectories that you specify with @option{-B}.Cross-compilers search a little differently:@itemize @bullet@item@file{real-ld} in the compiler's search directories.@item@file{@var{target}-real-ld} in @code{PATH}.@itemThe file specified in the @code{REAL_LD_FILE_NAME} configuration macro,if specified.@item@file{ld} in the compiler's search directories.@item@file{@var{target}-ld} in @code{PATH}.@end itemize@code{collect2} explicitly avoids running @code{ld} using the file nameunder which @code{collect2} itself was invoked. In fact, it remembersup a list of such names---in case one copy of @code{collect2} findsanother copy (or version) of @code{collect2} installed as @code{ld} in asecond place in the search path.@code{collect2} searches for the utilities @code{nm} and @code{strip}using the same algorithm as above for @code{ld}.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -