linux gcc compile options used Daquan + to create and use a dynamic library static library

Original link: https://blog.csdn.net/a568478312/article/details/79195218

-c: Only activate preprocessing, compilation, and assembly, will generate obj file
-S: only activate pre-processing and compilation, refers to a document compiled into assembly code.
-E: pre-activation only, does not generate a document, you need to redirect him to an output document.
-o: custom target name, the default document when gcc compiler is a.out
-ansi: Close gnu c and ansi c not compatible with the characteristics of activation ansi c proprietary features.
-Dmacro: #define macro C language equivalent to the
-Dmacro = defn: #define macro C language equivalent to the defn =
-Umacro: equivalent #undef macro C language
-Idir: Specifies the path to the file header
-I: Specifies the include file containing search directory
-llibrary: Specifies the library
-Ldir: custom compile time, the library search path.
-g: instructs the compiler, at compile time, generate debugging information.
-static: This option would prohibit the use of dynamic libraries, so the compiler out of something, generally large.
-share: This option will make use of dynamic libraries, generating documents is relatively small, but the system needs a dynamic library.
-O0 -O1 -O2 -O3: 4 levels of compiler optimization options, -O0 indicating no optimization, -O1 default value, -O3 optimization level highest
-Wall: will open some warning option is useful, it is recommended add a compile-time option.
-std: C specified criteria, such as the use -std = c99 c99 standard, -std = gnu99, C99 plus some extensions using the GNU.

advanced options

-v: Each output option detailed used during compilation
-C: retention annotations pretreatment
-ggdb: contains the executable file for debugging information GDB used
when compiled into assembly language: -fverbose-asm , the name of the C variable as a compilation of comments language
-save-temps: pretreatment automatic output file, assembly files, object files compiled normally
-fsyntax-only: test only source file syntax is correct, the compiler will not make any operation
-ffreestanding: independently compiled into the program, the host program not

Language Standard

-ansi: ANSI standard
-std = c99: C99 standard
-std = gnu89: ISO / IEC 9899 : 1990 and GNU expansion
-std = gnu99: ISO / IEC 9899 : 1999 and GNU expansion
-trigraphs: three-character ISO C support group

Error message
-w: Ignore any warnings

-Werror: does not distinguish between warnings and errors encountered any warnings to stop compile
-Wall: open most of the warning
-Wshadow: warning (warning this is not the time for a statement block scope variables with the same name as another variable larger scope included in -Wall option, the need to open separate)
-Wextra: a warning for all legal but questionable expression

Optimization options

-O0: Close all optimization options
-O1: first level optimization, this option makes executable files smaller, run faster, and does not add much compilation time, can be abbreviated as -O
-O2: second level optimization, using almost all of the optimization techniques, the use of this option will extend the compile time
-O3: third level optimization, increase the generation of inline function on the basis of -O2, using registers and other optimization techniques
-Os: this option is similar - O2, the role is to optimize the space occupied, but not optimized for performance, often used to produce the final version

Custom extensions

-x: Use this option to specify the file from the source defined extension types c, c-header, cpp- output, assembler, assembler-with-cpp, none
of all the documents listed in the back will be considered where -x its type is specified, in order to change the type can once again use the -x option, or use the -x none back to the default settings
example: gcc -o test test.c -x assembler test.asm -xc test2.c

Create and use static libraries

For example to create a static library static_lib.a
writing C source file static_lib.c, which need to write a function called repeatedly, then use the command gcc -c static_lib.c generate the target file static_lib.o
create a static library using ar tool, command format : ar rcs static_lib.a static_lib.o
write C header file static_lib.h, wherein the write prototype declaration for these functions
to write the main function app.c, include headers static_lib.h, so that normal use of the reusable custom function with the
use of command gcc app.c -static ./static_lib.a -o app compiled executable app

Creating and using shared libraries

Share_lib.so for example to create a dynamic library
written in C source files share_lib.c, you need to write a function called repeatedly, then use the command gcc -shared -fPIC -o share_lib.so share_lib.c generate dynamic library files share_lib.so
written in C header share_lib.h, write a function prototype declaration
to write the main function app.c, the introduction of the first document share_lib.h, then you can call custom functions in a dynamic library
using the command gcc app.c ./share_lib.so -o app compiled executable app

gcc compiler compiler option Daquan

https://blog.csdn.net/a568478312/article/details/79195218

Guess you like

Origin blog.csdn.net/qq_34595352/article/details/102744765