List of common command line parameters of GCC compiler

Source: Internet
Author: User
Do you know these commonly used gcc/g ++ command line parameters?

1. GCC-e source_file.c
-E: Only pre-compiled. Directly output the pre-compilation result.

2. GCC-s source_file.c
-S: only convert the source code to the assembly code and output the assembly code.

3. GCC-C source_file.c
-C: only compile and output the target file.

4. GCC (-E/S/C/) source_file.c-O output_filename
-O: Specifies the output file name, which can be used with the preceding three tags.
-O parameters can be omitted. In this case, the compiler uses the following default name for output:
-E: the pre-compilation result will be output to the standard output port (usually the display)
-S: Generate assembly code named source_file.s
-C: generate the target file named source_file.o.
No tag: generate an executable file named A. Out.

5. GCC-G source_file.c
-G: generate an executable file for the trial of commissioning, which can be run in GDB. Because the file contains debugging information, the running efficiency is very low and the file size is large.
Here, you can use the Strip command to delete the debug information in the file again. This will find that the generated file is even smaller than the output of the normal compilation, because strip also deletes some additional information (such as the function name) in the original normal compilation. Use strip A. Out

6. GCC-s source_file.c
-S, which directly generates executable files with the same effect as strip (all symbolic information is deleted ).

7. GCC-O source_file.c
-O (uppercase letter O), the compiler automatically optimizes the compilation of the code, and outputs executable files with higher efficiency.
-O can be followed by numbers to specify the optimization level, for example:
Gcc-O2 source_file.c
The larger the number, the more optimized. But in general, automatic things are not too clever. A large optimization level may cause a series of bugs in the generated files. Generally, you can select 2; 3 may be risky.

8. GCC-wall source_file.c
-W: enable some additional warning information during compilation. -Wall: Enable all warning information.

9. GCC source_file.c-L/path/to/lib-LXXX-I/path/to/include
-L: Specifies the function library used. In this example, the linker attempts to link the function library named libxxx..
-L: Specifies the folder where the function library is located. In this example, the linker searches for the/path/to/lib folder.
-I: Specifies the folder where the header file is located. In this example, the pre-compiler will try to search for the/path/to/include folder.

If you are interested, you can view the GCC manpage and find more details.

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.