Home > System Tutorial > LINUX > c/c++ compiler running process based on command line input

c/c++ compiler running process based on command line input

WBOY
Release: 2024-06-01 21:57:27
Original
965 people have browsed it

Table of contents

First: c/c compiler gcc, cc, c, g included in linuxgcc

Second: gcc features

Third: gcc running process

Fourth: gcc option

Fifth: Some of the agreed rules followed by gcc

First: c/c compiler gcc, cc, c, g included in linuxgcc

Among them, gcc and cc are the same, c and g are the same, usually c language programs are compiled with gccHow to compile with gcc in linuxHow to compile with gcc in linux, c The program is compiled with g.

Second: gcc features

gcc is a portable compiler that supports multiple hardware platforms. Such as ARM, X86, etc.

编译用英语怎么说_编译用英语_linux怎么用gcc编译

In addition to being a local compiler, gcc can cross-compile across platforms. The so-called local compiler means that the compiled program can only be run in the local environment. Only programs compiled by gcc can be run on other platforms.

gcc has multiple language backends for parsing different languages. In addition, gcc is a Linux vi command designed according to modularity, and can add support for new languages ​​and new CPU architectures. gcc is free software. Anyone can use or modify this software.

Third: gcc running process

(1) Enter on the command line: gcctest.c

This will compile a program named a.out by default,

Then enter on the command line: ./a.out

You can run the program.

(2) If you enter on the command line: gcctest.c-otest

This will compile a program named test

Then enter on the command line: ./test

You can run the program.

Note: The -o parameter is used to specify the name of the generated program

(3) Step by step implementation of the linux operating system version, more specific image

It contains 4 processes:

1.Preprocessing

Essentially, 4 operations will be performed (including expansion of header files, removal of comments, macro replacement, conditional compilation),

Specific operation: Command line input: gcc-Etest.c-otest.i

This command means: after the first step of preprocessing, it will stop and the temporary content will be stored in the test.i file

linux怎么用gcc编译_编译用英语_编译用英语怎么说

2.Compile

The essence is to turn c language into assembly language

Specific operation: Command line input: gcc-Stest.i-otest.s

This command means: After the second step of compilation, it will stop and the temporary content will be stored in the test.s file

3.Compilation

The essence is to turn assembly language into a target two's complement file (not executable)

Specific operation: Command line input: gcc-ctest.s-otest.o

The meaning of this command is: it will stop after the third step of assembly, and the temporary content will be stored in the test.o file

4.Link

linux怎么用gcc编译_编译用英语_编译用英语怎么说

The essence is to introduce the third-party libraries we use in the code to generate executable files or library files

(Third-party libraries are determined by the compiler and file suffix)

Fourth: gcc option

-E only performs preprocessing operations

-S compile to assembly stop (no assembly, only preprocessing and compilation completed)

-c performs assembly operations (compile to assembly code)

-O[0,1,2,3]

Optimization program (default is level 2 optimization, 0 is not optimized, 3 is the highest optimization level)

-static uses static linking for generated files

编译用英语怎么说_linux怎么用gcc编译_编译用英语

-shared try to use dynamic libraries

-Idir

Add the dir directory to the directory path of the search header file

-Ldir

Add the dir directory to the directory path of the search library

-llib

Connect lib library

-Wall causes gcc to issue warning messages for code problems in source files

-WDo not issue a warning message

-g generates debugging information in the target file to facilitate debugging by debuggers such as gdb

The above is the detailed content of c/c++ compiler running process based on command line input. For more information, please follow other related articles on the PHP Chinese website!

source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template