Common compilation Commands summary _c language under C/C + + compiler GCC

Source: Internet
Author: User

Brief introduction
gcc means gun C Compiler. After years of development, GCC has not only supported the C language, it also now supports the ADA, C + +, Java, objective C, Pascal, COBOL, and Mercury languages that support functional programming and logical programming, and so on. And GCC is no longer simply gun the meaning of the C language compiler, but became a gun complier collection is also the meaning of the gun compiler family. On the other hand, when it comes to GCC's support for operating system platforms and hardware platforms, it is summed up in the same sentence: ubiquitous.


compiling
the sample program is as follows:

  #include <stdio.h> 
   
  int main (void) { 
    printf ("Hello world!\n"); 
   
    return 0; 
  } 


This program, one-step's compilation instructions are:

  Gcc-o Test test.c 


In essence, the above compilation process is divided into four phases:

    1. Preprocessing (also known as precompilation, preprocessing)
    2. Compiling (Compilation)
    3. Compilation (Assembly)
    4. Connection (linking)


pretreatment

  GCC-E test.c-o test.i or GCC-E test.c 


You can output test.i files that contain test.c code that is preprocessed. Open the Test.i file and take a look at it and you'll see. The following instruction is to output the preprocessed code directly in the Command line window.

The-e option of GCC allows the compiler to stop after preprocessing and output preprocessing results. In this case, the preprocessing result is to insert the contents of the stdio.h file into the test.c.

Compile to assembly code
after preprocessing, you can compile the generated test.i file directly, generating assembly code:

  Gcc-s Test.i-o Test.s 


The-s option of GCC, which means that when the assembly code is generated, the-O output assembly code file is stopped when the program is compiled

Assembly
for the assembly code file generated in the previous section, the Test.s,gas assembler is responsible for compiling it as the target file, as follows:

  Gcc-c Test.s-o TEST.O 


Connection
The GCC connectors are provided by gas and are responsible for connecting the target files of the program to all of the additional target files required, resulting in an executable file. Additional target files include static connection libraries and dynamic connection libraries.

For the TEST.O generated in the previous section, connect it to the C standard Input output library, and eventually build the program test

  GCC Test.o-o Test 


Executes in a command line window./test, let it say hello world!


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.