C language compilation process and GCC compilation parameters

Source: Internet
Author: User

C language compilation generally has three steps:

    1. Pre-compilation:

GCC-E-O A.E a.c

Precompiled A.C file with the resulting target file named A.E

Precompilation is to replace the contents of the header file contained in the include with the C file, while deleting the unused comments in the code

Example:

Main.c

#include <stdio.h>

#include "sum.h"

int main () {

int m = 6;

int n = 5;

int result = SUM (m,n); printf ("hello\n%\n", result);

Sum.h

int sum (int x,int y);

After running the result is:

The first step is this!

2. compiling

Gcc-s-O a.s a.e

Translate the A.E into an ASCII assembly-language file A.S.

3. Links

Gcc-o a A.S

This line of command tells GCC to link the source program A.O to generate an executable program a

GCC does not have any parameters, indicating that it is a link

The basic options for the GCC compiler are the following table:

Type Description
-E Stop after preprocessing, do not compile, assemble, and connect
-S Stop after compiling, do not assemble and connect
-C Compile or assemble the source file without connecting
-O File Specifies the output file

C-language include header file

    1. Include is to tell the compiler that it contains a header file
    2. In the C language, any library function call needs to contain a header file
    3. Header files are also equivalent to a document declaration
    4. If you put the main function in the first file and put the custom function in the second file, you need to declare the function prototype in the first file.
    5. If a function prototype is included in a header file, then it is not necessary to declare its prototype every time the function is used, it is a good habit to put the function declaration into the header file!
    6. Header files may not need to be compiled
    7. You can view the specific statement
    8. The header file plus the O file of the implementation file is submitted to the user, no need to know the source code
    9. o files are precompiled, so the compilation time is greatly improved when the whole project is compiled.
    10. When a file (A.C file) is dependent on the header file (b.h), A.O files do not need to be recompiled if the B.O files formed after B.C compilation are recompiled
    11. Can greatly reduce the chance of errors in manual copying and pasting

Considerations for header files:

    1. < header file, indicating that the C language compiler looks for related header files under the system directory (that is, the include directory of the GCC compiler)
    2. "Header file" for the C language compiler to look for related header files in the user's current directory
    3. If it is a required header file that uses the C library function, it must be #include<>
    4. If the user-defined header file is used, it must be # include ""

C language compilation process and GCC compilation parameters

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.