Linux GCC Common commands

Source: Internet
Author: User


The meaning of GCC is only GNU C Compiler. After so many years of development, GCC has not only supported the C language; it now also 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 just the GNU C language compiler meaning, but into the GNU Compiler Collection is also the GNU compiler family meaning. On the other hand, when it comes to GCC's support for operating system platforms and hardware platforms, it is a word: ubiquitous.


It is divided into four phases, i.e. preprocessing (also known as precompilation, preprocessing), compilation (compilation), assembly (Assembly), and connection (linking).


1 preprocessing
CC-E test.c-o test.i or GCC-E test.c
You can output the code in the Test.i file that contains the test.c after preprocessing. Open the Test.i file and take a look, and you'll see. The subsequent 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 the preprocessing results. In this case, the preprocessing result is to insert the contents of the stdio.h file into the test.c.


2 Compiling to Assembly code (compilation)
After preprocessing, you can compile the generated test.i file directly and generate the assembly code:


Gcc-s Test.i-o Test.s
The-s option of GCC, which indicates that the assembly code is stopped and the-O output assembly code file is generated during program compilation.


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


Gcc-c Test.s-o TEST.O
4 Connection (linking)
The GCC connector is provided by gas and is responsible for connecting the program's target file with all the additional target files needed to eventually generate the executable file. Additional target files include a static connection library and a dynamic connection library.


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


GCC Test.o-o Test



In the command line window, execute the./test!


Compilation of more than 3 program files


Typically, the entire program is composed of multiple source files, which in turn form a number of compilation units, which can be well managed using GCC. Suppose you have a program that consists of two source files of test1.c and test2.c, in order to compile them and eventually generate executable test, you can use this command:


GCC test1.c test2.c-o Test


If more than one file is processed at the same time, GCC will still follow the process of preprocessing, compiling, and linking. If you delve into it, the above command is roughly equivalent to executing the following three commands in turn:


Gcc-c Test1.c-o TEST1.O
Gcc-c Test2.c-o TEST2.O
GCC test1.o test2.o-o Test

Linux GCC Common commands

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.