Linux GUN gcc compilation four processes: preprocessing, compiling, compiling, linking

Source: Internet
Author: User

Reference Blog: http://www.cnblogs.com/qytan36/archive/2010/05/25/1743955.html

GCC compiled c source code has four steps: preprocessing-----> Compiling----> Assembly----> Links

Four-stage function: (the corresponding file suffix is in sequence:. I>.s>.o>.exe)

The code of the introduced header file is added to the current file. Option "-e" preprocessing. Usage: gcc-e hello.c–o hello.i

"To compile GCC first to check the code's normative, whether there are grammatical errors, etc., after the inspection is correct, GCC translated the code into assembly language. Option "-S" preprocessing. Usage: gcc-s hello.i–o Hello.s. (this option is compiled without assembly, generating assembly code.) )

The assembler stage is to turn the ". S" file generated during the compilation phase into binary target code. Option "-C" preprocessing. Usage: gcc-c hello.s–o hello.o.

Link after a successful compilation, the link stage is entered. No option link usage: gcc hello.o–o hello.exe.

Comments:

In the link stage, the compiler is in fact the system standard header files corresponding to the implementation of the corresponding link library, such as stdio.h corresponding to the library file named Libc.so.6, link into their own assembly generated by the. o file. Finally, the executable program is generated.

You can use the LDD command to view the dynamic library load situation.

function library is generally divided into static library and dynamic library two kinds. Static library refers to the compilation of links, the library files of the code are all added to the executable file, so the resulting file is relatively large, but at run time also no longer need the library file. The suffix is generally ". a". Dynamic libraries In contrast, when compiling a link does not add the code of the library file to the executable file, but the library is loaded by the runtime link file when the program executes, which can save the system overhead. The general suffix of the dynamic library is named ". So", as described in the previous libc.so.6 is a dynamic library. GCC uses dynamic libraries by default at compile time.

Linux GUN gcc compilation four processes: preprocessing, compiling, compiling, linking

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.