Common gcc commands

Source: Internet
Author: User

1. Common linux gcc commands

No options

Gcc test. c

Prepare, compile, and link test. c to form an executable file.

-O file name
Compile as the target code
-C
Compile only the source file without link, for example, gcc-c test. s. You can output the Assembly file as a test. o file.

-S

Generate assembly code

-E

Program preprocessing is output as a. I file, for example: gcc-E test. c-o test. I

Gcc file name 1 file name 2-o file name

Compilation of multiple program files, for example, gcctest1.c test2.c-o test

Compile multiple program files. You can also use

Gcc-c test1.c

Gcc-c test2.c

Gcc-o test1.o-o test2.otest

-D foo = X
Define the pre-processing macro FOO in the command line, whose value is X
-I dir
Add a header file search path
-L dir
Add library file search path

-Static
Link Static Library

-Library

Link Library File
-G
Include standard debugging information in executable programs
-Ggdb
Generate debugging information for gnu identification only
-O number
Specify the code optimization level as N, 0 <= N <= 3. -O1 tells the compiler to perform the first-level optimization. Generally, increasing the optimization level will make the program run faster, but the Compilation Time will be longer, making it more difficult to debug the program with a debugging tool, using a higher level of optimization Code makes the generated machine code hard to understand.
-Ansi
Supports ANSI/iso c standard syntax
-Pedantic
All warnings listed in ANSI/iso c are allowed
-Pedantic-errors
All errors listed in ANSI/iso c standards allowed
-Traditional
Supports K & r c syntax;
-W
Disable all warnings
-Wall
Allow all useful warnings provided by gcc
-Werror
Converts all warnings to errors and terminates the compilation process when a warning occurs.

2. The file name suffix stipulated by gcc:

. C language source code file

. A library file consisting of the target file

. Cc C ++ source code file

Files produced by. I preprocessing

C ++ source code files produced by. ii preprocessing

. O target file

. S assembly code file

3. Compile the C ++ program in ubuntu

First install g ++ in ubuntu and run the sudo apt-get sudo g ++ command.

Then write the program source code and save it as a. cpp file. Use the command gcc-o target file name to generate the. out file and then run the program in the. out file. For example:

# Include <iostream>

Using namespace std;

Int main ()

{

Cout <"hello world" <endl;

Return 0;

}

Save as hello. cpp, and then use g ++-o hello. cpp,

Then execute./hello to output hello, world


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.