GCC for Linux Compiler

Source: Internet
Author: User

GCC for Linux Compiler

In the previous section, we learned the Vim editor. Next we will learn the gcc compiler. Here, we need to differentiate between the editor and the compiler?

Editor refers to the code that I use to write a program (edit code). The Code statements we write are not understood by the computer, and we need to convert them into statements that can be understood by the computer, the compiler is such a conversion tool. That is to say, we can use the editor to compile the program and run it only after compilation!

A compiler is a program that translates high-level computer languages that are easy to write, read, and maintain into low-level machine languages that computers can interpret and run.

GCC (GNU Compiler Collection, GNU Compiler suite) is a programming language Compiler developed by GNU. As the official compiler of the GNU operating system, GCC has been adopted as a standard compiler by most Unix-like operating systems (such as Linux, BSD, and Mac OS X, GCC is also applicable to Microsoft Windows.

GCC was originally used to compile the C language, with the development of the project, GCC has become a compiler family capable of compiling C, C ++, Java, Ada, fortran, Object C, Object C ++, And Go languages.

Here is a brief introduction to how to compile a C program or C ++ program to eventually become an executable program.

Download the sample code.

------------------------------------------ Split line ------------------------------------------

Free in http://linux.bkjia.com/

The username and password are both www.bkjia.com

The specific download directory is/July 6,/July 7/Linux compiler GCC/

For the download method, see

------------------------------------------ Split line ------------------------------------------

The file extensions recognized by gcc are as follows:

. C language file

. I pre-processed C language file

. C,. cc,. cp,. cpp,. c ++,. cxx C ++ language file

. Ii pre-processed C ++ language files

. S Assembly file (user-created Assembly file)

. S pre-processed Assembly File

. O compiled target file

. A static Link Library of the target file (used for linking)

. So Dynamic Link Library of the target file (used for linking and running)

Compilation process of gcc and g ++ Compiler

1. Preprocessing

2. Compile

3. Assembly

4. Links

Gcc common compilation application example

Step-by-step compilation:

1) gcc-E hello. c-o hello. I

2) gcc-S hello. I-o hello. s

3) gcc-c hello. s-o hello. o

4) gcc hello. o-o hello_elf

Compilation option description:

-O file: specifies that the generated output file name is file.

-E only performs preprocessing.

-S only performs preprocessing and compilation.

-C only performs preprocessing, compilation, and compilation.

File name suffix description:

. C language file

. I pre-processed C language file

. S pre-processed Assembly File

. O compiled target file

After the program is compiled, run the executable program through.

Commonly used compilation (or the process of preprocessing, compilation, compilation, and linking ):

Gcc hello. c-o demo

For C ++ code, you only need to use the g ++ compiler.

If you do not have the g ++ compiler, install it online:

Use g ++ to compile c ++ programs:

Other options for gcc and g ++ Compilation

-V displays the configuration commands used to create the gcc tool, and displays the version numbers of the Preprocessor and compiler.

-Wall: generates warnings of all levels

-W: Disable all warnings. This option is not recommended.

-Idir: add the dir directory to the header file search directory list. First, find the contained header file in the dir directory.

-Ldir: add the dir directory to the directory list of the imported files, and search for the library files in the dir directory first.

-The library with the lname Link Library name

-Use static libraries for static links

-Shared compiling of dynamic libraries

Linux GCC 4.8.1 clear and concise tutorial (Ubuntu 12.04 64-bit edition as an example)

Compile and install GCC 4.8.1 + GDB 7.6.1 + Eclipse in CentOS 6.4 and compile and install GCC 4.8.1 + GDB 7.6.1 + Eclipse in CentOS 6.4

Install and use Vim + GCC + GDB in Ubuntu

Switch two GCC versions in Ubuntu

CentOS6.5 upgrade to manually install GCC4.8.2

GCC details: click here
GCC: click here

This article permanently updates the link address:

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.