The GCC and g++ compilers for Linux

Source: Internet
Author: User

1.GCC compiler

The GCC compiler was initially developed for the C compiler (GNU C Compiler), but over time the GCC compiler was able to support multiple languages.

1.1 Use of the GCC compiler

If we already have a. c file name is called HELLO.C, you can use the following statement to compile the file:

$ gcc hello.c

After the statement executes successfully, the executable file name is generated in the current directory called a.out (the default), and we can use the following statement to run the executable:

$./a . Out

Of course we don't want to use the default name, which is not intuitive enough for us to specify its executable file name when we compile with GCC:

$ gcc-o Hello hello.

The default a.out file name is replaced with "Hello";

1.2 Compiling relevant options

In many cases the programmer does not want an executable file so simple, some situations require the target code, some occasions need to assemble the code and so on, the following list of compiler-related options:

-C only activates preprocessing, compilation, and assembly, and generates a target code file with an. o extension;

-S only activates preprocessing and compilation, generating assembly code files with the extension. S;

-e only activates preprocessing and outputs the result to standard output

-G generates related information (such as GDB) for the debugger

1.3 Optimization Options

GCC offers 3 levels of optimization for programmers to choose from, from low to high in turn-o1,-o2 and-o3. Theoretically, the-O3 can generate the most efficient code, but the higher the degree of optimization the higher the risk, the more often the-O2 is used. In fact, the three-level optimization is packaged for a variety of specific optimizations, specific to the GCC official manual, and using the-march option to compile binary code for a specific CPU, but not for special occasions do not use the-march option.

$ gcc-o2-o Hello hello.c

2.g++ compiler

Although GCC can compile C + + source files, it cannot automatically connect to C + + libraries, so it is common to use g++ to compile and link C + + source files.

Use of the g++ compiler

The use of the g++ compiler is basically consistent with GCC.

The GCC and g++ compilers for Linux

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.