Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use gcc command under Linux system

2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use the gcc command under the Linux system". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the gcc command under the Linux system".

Installation of 1.gcc (take Ubuntu as an example) sudo apt-get install build-essential

After installation, you can view the version through gcc-- version.

Let's master the basic application of the executable file in the process of compiling it through gcc.

Prepare: first create a new .c file such as 666.c using vim in the current directory

$vim 666.c

(the use of vim can be described in detail in another blog post, which will not be repeated here.)

Insert a piece of code.

# include main () {int areci; axiom6; for (iPretreatment file name)

For example, according to 666.c, the preprocessing can be:

Gcc-E 666.c-o 666.i

It can also be gcc 666.c > 666.i

two。 Compile

1. Compilation is to check whether the syntax is wrong or not, and compile the preprocessed file into an assembly file.

two。 Command:

$gcc-S (source file)-o (assembly file)

For example, gcc-S 666.I-o 666.s

three。 Compilation

1. Assembler is to generate an assembly file into an object file (binary file) through assembly, and the text code becomes binary code. (the binary code file has the suffix .o).

two。 Command:

$gcc-c (assembly file)-o (object file)

For example, gcc-c 666.s-o 666.o

(at this time, it will be garbled because it is a binary file.)

four。 Link

1. The link finds the dependent library file (static and dynamic) and links the target file as an executable program.

$gcc-c [object file]-o [executable]-l [dynamic library name]

If there is no dynamic library (general)

direct

$gcc-c [object file]-o [executable program]

For example, gcc-c 666.o-o 666

The executable program 666 is generated

If you want to execute using this command:

$. / executable program

Where. / means in the current directory.

For example. / 666

(note: in general, if we use the gcc executable file name, the a.out executable file will be generated by default. / a.out will be used when we execute it directly.)

Thank you for your reading, the above is the content of "how to use the gcc command under the Linux system". After the study of this article, I believe you have a deeper understanding of how to use the gcc command under the Linux system. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report