Talk GCC together (second: GCC), talkgcc

Source: Internet
Author: User

Talk GCC together (second: GCC), talkgcc


Hello, everyone. The last time we introduced GCC briefly. Let's talk about how to use GCC later,

The words are right. Let's talk GCC together!


In the last session, we only talked about the GCC Compilation Principle and didn't talk about how to use GCC for compilation. It was also a theory and there was no example,

It may be a bit itchy. In this case, let's talk about how to use GCC. In fact, GCC is the same as other software on Linux,

The command line is also used for operations. So let's talk about the GCC command line format: gcc option parameter. You can select

Items and parameters can also be multiple options and parameters, or the option can be left blank. Of course, there must be no fewer parameters, because

It is a compiled file. How can I compile a file without compilation? It's hard to have a cup of cake!


No option. There are only example parameters:Gcc filename. c This command indicates using GCC to compile a file named filename. c. After compilation

A file named a. out is generated. This file is the target file and can be run directly in the system. Running Method:./a. out.


An example of options and parameters:Gcc filename. c-o f this command indicates that the file named filename. c is compiled using GCC.

Then, a file named f. o is generated. This file is the target file and can be run directly in the system. Running Method:./f. o. In this example

Option o enables GCC to generate the target file named f. o, instead of using the default target file name, a. out.


Example of one option and two parameters:Gcc file1.c file2.c-o f this command indicates using GCC to compile files named file1.c and file2.c

And generate the target file named f. o. The option in this example is still o, so I will not talk about it much.


Example of two options and one parameter:Gcc-O2 file1.c-o f this command indicates using GCC to compile a file named file1.c.

Generate the target file named f. o. In this example, the options are o and O (note that they are uppercase O). Option o is not much mentioned, and option O indicates that GCC is enabled.

Optimize the code. The optimization level is 2. We will introduce the Optimization content in the following chapter. Here we regard it as a part of GCC.

You can use it to illustrate how GCC uses two options for compilation. If you have other options, you can

Put it before or after option O in the example. If there are multiple parameters, they can be placed after file1.c. After such expansion

You can use GCC to compile multiple options and multiple parameters. The specific example will not be mentioned.


Through the examples listed above, I think you have learned how to use GCC for compilation. Take two measures when using GCC

The key point is: one is the GCC option, and the other is the GCC parameter. The parameter is essentially the source file of the program compiled by GCC,

This is easy to understand. The number of parameters can be the same as in the example. There are many GCC options, and each

Options have different usage, which is difficult to grasp. If you have mastered the GCC options, we can be proficient

To use GCC for compilation.


Finally, with the use of GCC, I share my own sentiment: In a Linux environment, when using each application software or Linux Command,

First, you must master the Command Format and then the Command Options. The format is a form. If you use it more often, you will be familiar with it. For example

If you use less, forget it, and it doesn't matter where it is, MAN can think of it. What is hard to grasp is the Linux Command option, because

The use of commands is essentially the use of various options in the command. Different options have different usage. Different Options reflect the Linux Command does not

Same function. With flexible use of various options, you can master various software or Linux commands.


Let's talk about GCC today. I want to know what to do later, and listen to the next decomposition!


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.