"Linux" gcc command

Source: Internet
Author: User

Source: HTTP://MAN.LINUXDE.NET/GCC

Grammar

GCC Options Parameters

Options

-o: Specifies the generated output file;-E: performs only compile preprocessing;-S: Converts C code to assembly code;-Wall: Displays a warning message;-C: Only the compilation operation is performed. The connection operation is not performed.

Parameters

C Source file: Specifies the C language source code file.

Suppose the source program file is named TEST.c

No option to compile links

gcc test.c

Preprocess, assemble, compile, and link test.c into an executable file. The output file is not specified here, and the default output is a.out.

Option-O

gcc test.c-o test

Preprocess, assemble, compile, and link test.c to form the executable test. The-o option is used to specify the file name of the output file.

Option-E

gcc -e test.c-o test.i

The test.c preprocessing output test.i file.

Option-S

gcc -S TEST.I

Assembles the preprocessed output file test.i into a test.s file.

Option-C

gcc -C TEST.S

The assembly output file Test.s compiled output TEST.O file.

No option link

gcc test.o-o test

Link the compiled output file TEST.O to the final executable test.

Option-O

gcc -o1 test.c-o test

Compile the program using the Compile Optimization level 1. The higher the level, the better the optimization effect, but the longer the compilation time.

Methods of compiling multi-source files

If you have more than one source file, there are basically two ways to compile: Suppose there are two source files for TEST.c and TESTFUN.C

Compiling multiple files together

gcc testfun.c test.c-o test

Compile testfun.c and test.c separately and link them to the test executable file.

Compile each source file separately, and then link to the target file for the post-compilation output.

gcc -c testfun.c #将testfun. C compiled into TESTFUN.Ogcc -c test.c #将test. C compiled into TEST.Ogcc -o testfun.o test.o-o test #将testfun. O and TEST.O link to test

The above two methods compare, the first method compiles all the files need to recompile, and the second method can only recompile modified files, unmodified files do not have to recompile.

From: HTTP://MAN.LINUXDE.NET/GCC






"Linux" gcc command

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.