GCC command-line options

Source: Internet
Author: User

Http://tigcc.ticalc.org/doc/comopts.html

Source: http://www.ruchee.com/code/linux/gnu/gcc.html

Common options

-E: Only preprocessing, not compiling
-S: Compile only, not assemble
-c: Compile and assemble only, without Link
-g: Contains debugging information
-I: Specify the search directory for include files
-o: Output to the specified file name

Advanced options

-v: Detailed output of each option used in the compilation process
-C: Retained comments during preprocessing
-ggdb: Include available in the executable fileGDBDebugging information used
-fverbose-asm: The name of the C variable is used as a comment in the assembly language during compilation and translation.
-save-temps: Automatically outputs pre-processing files, assembly files, and object files. Compilation is normal.
-fsyntax-only: Only test whether the source File Syntax is correct. No compilation operation is performed.
-ffreestanding: Compiled into an independent program, not a Host Program

Language Standards

-ansi: ANSI standard
-std=c99: C99 Standard
-std=gnu89: ISO/IEC 9899: 1990 and GNU Extension
-std=gnu99: ISO/IEC 9899: 1999 and GNU Extension
-trigraphs: Supports three-character Iso c Group

Error prompt

-w: Ignore all warnings
-Werror: Warning and error are not distinguished. If any warning is encountered, compilation stops.
-Wall: Enable most warning messages
-Wshadow: A warning is issued when the block scope variable of a statement has the same name as another variable in a larger scope (this warning is not included in-WallOption, which must be enabled separately)
-Wextra: Warns of all valid but suspicious expressions

Optimization Options

-O0: Disable all Optimization Options
-O1: Level 1 Optimization. Use this option to make the executable file smaller and run faster without increasing the Compilation Time.-O
-O2: Second-level optimization, using almost all optimization technologies, this option will prolong the Compilation Time
-O3: Level 3 optimization, in-O2AddedinlineFunctions, registers, and other optimization technologies
-Os: This option is similar-O2It is used to optimize the space occupied, but does not optimize the performance. It is often used to generate the final version.

Custom Extension

-x: You can use this option to specify the custom source file extension.c,c-header,cpp-output,assembler,assembler-with-cpp,none

Van-xAll the files listed below will be treated as the specified type. To change the type, you can use-xOption, or use-x noneBack to default settings

Example:gcc -o test test.c -x assembler test.asm -x c test2.c

Creation and use of static databases

To create a static librarystatic_lib.aExample

  1. Compile C source filestatic_lib.cWrite the function that needs to be called repeatedly, and then use the commandgcc -c static_lib.cGenerate the target filestatic_lib.o
  2. UsearTool to create a static library, command format:ar rcs static_lib.a static_lib.o
  3. Compile C header filestatic_lib.h, And the prototype declaration written to these functions
  4. Compile the main functionapp.c, Introduce header filesstatic_lib.hIn this way, the User-Defined reusable functions can be used normally.
  5. Use commandsgcc app.c -static ./static_lib.a -o appCompile and generate executable filesapp
Dynamic library creation and use

To create a dynamic libraryshare_lib.soExample

  1. Compile C source fileshare_lib.c, Write the function that needs to be called repeatedly, and then use the commandgcc -shared -fPIC -o share_lib.so share_lib.cGenerate dynamic library filesshare_lib.so
  2. Compile C header fileshare_lib.h, Written to the prototype Declaration of the Function
  3. Compile the main functionapp.c, Introduce header filesshare_lib.hThen, you can call the custom functions in the dynamic library.
  4. Use commandsgcc app.c ./share_lib.so -o appCompile and generate executable filesapp

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.