每一个“丑得人神共愤”的泡妞高 手都有一颗坚忍的心,这证明了人类 在绝境中毫不妥协的求生精神,反正丑都丑了,索性放开手脚大干一场,这就叫“无产阶级失去的是锁链,得到的是全世界”
2013年(130)
分类: LINUX
2013-08-02 11:18:01
1.预处理,生成.i的文件[预处理器cpp][参数详解]
2.将预处理后的文件不转换成汇编语言,生成文件.s[编译器egcs]
3.有汇编变为目标代码(机器代码)生成.o的文件[汇编器as]
4.连接目标代码,生成可执行程序[链接器ld]
-E
只激活预处理(默认不生成文件,将结果输出到标准输出)
-S
只激活预处理和编译,将文件编译为汇编代码(默认生成a.s文件)
-c
只激活预处理,编译,和汇编,将文件做成目标文件(生成a.o文件)
-o file
将结果输出到文件file中
-Idir
增加头文件搜索目录
-v Verbose mode. Print out GNU CPP's version number at the beginning of execution, and report the final form of the include path.
-H Print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the #include stack it is.
Precompiled header files are also printed, even if they are found to be invalid; an invalid precompiled header file is printed with ...x and a valid one
with ...! .
-nostdinc
Do not search the standard system directories for header files.
-Ldir
增加-l的搜索目录
-llibrary
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not
recommended.)
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are
specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be
loaded.
The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it
had been specified precisely by name.
The directories searched include several standard system directories plus any that you specify with -L.
Normally the files found this way are library files---archive files whose members are object files. The linker handles an archive file by scanning
through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file,
it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with lib and .a
and searches several directories.
-print-search-dirs
Print the name of the configured installation directory and a list of program and library directories gcc will search---and don't do anything else.
-Wall
开启所有警告
制作共享库
-shared
Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results,
you must also specify the same set of options that were used to generate code (-fpic, -fPIC, or model suboptions) when you specify this option.[1]
-fpic
Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant
addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of
GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message
from the linker indicating that -fpic does not work; in that case, recompile with -fPIC instead. (These maximums are 8k on the SPARC and 32k on the m68k
and RS/6000. The 386 has no such limit.)
Position-independent code requires special support, and therefore works only on certain machines. For the 386, GCC supports PIC for System V but not for
the Sun 386i. Code generated for the IBM RS/6000 is always position-independent.
When this flag is set, the macros "__pic__" and "__PIC__" are defined to 1.
-fPIC
If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset
table. This option makes a difference on the m68k, PowerPC and SPARC.
Position-independent code requires special support, and therefore works only on certain machines.
When this flag is set, the macros "__pic__" and "__PIC__" are defined to 2.
-Wl,option
Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. You can use this syntax to pass an
argument to the option. For example, -Wl,-Map,output.map passes -Map output.map to the linker. When using the GNU linker, you can also get the same
effect with -Wl,-Map=output.map.
NOTE: In Ubuntu 8.10 and later versions, for LDFLAGS, the option -Wl,-z,relro is used. To disable, use -Wl,-z,norelro.
以下两个选项多用于交叉编译
-isysroot dir
This option is like the --sysroot option, but applies only to header files (except for Darwin targets, where it applies to both header files and
libraries). See the --sysroot option for more information.
--sysroot=dir
Use dir as the logical root directory for headers and libraries. For example, if the compiler would normally search for headers in /usr/include and
libraries in /usr/lib, it will instead search dir/usr/include and dir/usr/lib.
If you use both this option and the -isysroot option, then the --sysroot option will apply to libraries, but the -isysroot option will apply to header
files.
The GNU linker (beginning with version 2.16) has the necessary support for this option. If your linker does not support this option, the header file
aspect of --sysroot will still work, but the library aspect will not.
ld常用选项
-v
--version
-V Display the version number for ld. The -V option also lists the supported emulations.
--dll-verbose
--verbose[=NUMBER]
Display the version number for ld and list the linker emulations supported. Display which input files can and cannot be opened. Display the linker
script being used by the linker. If the optional NUMBER argument > 1, plugin symbol status will also be displayed.
-rpath=dir
Add a directory to the runtime library search path. This is used when linking an ELF executable with shared objects. All -rpath arguments are
concatenated and passed to the runtime linker, which uses them to locate shared objects at runtime. The -rpath option is also used when locating shared
objects which are needed by shared objects explicitly included in the link; see the description of the -rpath-link option. If -rpath is not used when
linking an ELF executable, the contents of the environment variable "LD_RUN_PATH" will be used if it is defined.
The -rpath option may also be used on SunOS. By default, on SunOS, the linker will form a runtime search patch out of all the -L options it is given. If
a -rpath option is used, the runtime search path will be formed exclusively using the -rpath options, ignoring the -L options. This can be useful when
using gcc, which adds many -L options which may be on NFS mounted file systems.
For compatibility with other ELF linkers, if the -R option is followed by a directory name, rather than a file name, it is treated as the -rpath option.
-rpath-link=dir
When using ELF or SunOS, one shared library may require another. This happens when an "ld -shared" link includes a shared library as one of the input
files.
When the linker encounters such a dependency when doing a non-shared, non-relocatable link, it will automatically try to locate the required shared
library and include it in the link, if it is not included explicitly. In such a case, the -rpath-link option specifies the first set of directories to
search. The -rpath-link option may specify a sequence of directory names either by specifying a list of names separated by colons, or by appearing
multiple times.
This option should be used with caution as it overrides the search path that may have been hard compiled into a shared library. In such a case it is
possible to use unintentionally a different search path than the runtime linker would do.
The linker uses the following search paths to locate required shared libraries:
1. Any directories specified by -rpath-link options.
2. Any directories specified by -rpath options. The difference between -rpath and -rpath-link is that directories specified by -rpath options are
included in the executable and used at runtime, whereas the -rpath-link option is only effective at link time. Searching -rpath in this way is only
supported by native linkers and cross linkers which have been configured with the --with-sysroot option.
3. On an ELF system, for native linkers, if the -rpath and -rpath-link options were not used, search the contents of the environment variable
"LD_RUN_PATH".
4. On SunOS, if the -rpath option was not used, search any directories specified using -L options.
5. For a native linker, the search the contents of the environment variable "LD_LIBRARY_PATH".
6. For a native ELF linker, the directories in "DT_RUNPATH" or "DT_RPATH" of a shared library are searched for shared libraries needed by it. The
"DT_RPATH" entries are ignored if "DT_RUNPATH" entries exist.
7. The default directories, normally /lib and /usr/lib.
8. For a native linker on an ELF system, if the file /etc/ld.so.conf exists, the list of directories found in that file.
If the required shared library is not found, the linker will issue a warning and continue with the link.