Introduction to Linux programming tools C compiler and C programming tools (1)

Source: Internet
Author: User

The Linux release contains many software development tools. many of them are used for C and C ++ application development. this article describes the tools that can be used for C application development and debugging in Linux. the purpose of this article is to introduce how to use the C compiler and other C programming tools in Linux, rather than the C Programming Tutorial.

Linux programming tool gnu c Compiler

Linux programming tool gnu c compiler (GCC) is a fully functional ansi c compatible compiler. if you are familiar with a C compiler on other operating systems or hardware platforms, you will be able to quickly master GCC. this section describes how to use GCC and some of the most common options for GCC compilers.

Use GCC for Linux programming tools
The basic usage of the GCC compiler. gcc command is usually followed by some options and file names:
Gcc [options] [filenames]
The operation specified by the command line option will be executed on each given file on the command line. The next section describes the options you will most commonly use.

GCC options for Linux programming tools
GCC has more than 100 compilation options available. many of these options may never be used, but some of the main options will be frequently used. many GCC options include more than one character. therefore, you must specify the respective characters for each option, and, just like most Linux commands, you cannot separate the characters with a group of options. for example, the following two commands are different:
Gcc-p-g test. c
Gcc-pg test. c

The First Command tells GCC to compile test. in c, the profile information is created for the prof command and the debugging information is added to the executable file. the second command only tells GCC to create profiling information for the gprof command.
When you do not need any options to compile a program, GCC will create (assuming the compilation is successful) a program named. out executable file. for example, the following command will generate. out file:
Gcc test. c
You can use the-o compilation option to specify a file name for the generated executable file instead of. out. for example. the c program of C is compiled into an executable file named count. Enter the following command:
Gcc-o count. c

The Linux programming tool GCC also has the compilation option to specify how much the compiler processes. -c indicates that GCC only compiles the source code as the target code and skips the Assembly and connection steps. this option is frequently used because it makes compilation of multiple C Programs faster and easier to manage. the target code file created by GCC is missing. o Extension.

The-S compilation option tells GCC to stop compiling after an assembly language file is generated for C code. the default extension of assembly language files generated by GCC is. s. -E indicates that the compiler only processes the input file. when this option is used, the pre-processor output is sent to the standard output instead of stored in the file.

Optimized items

When you use the Linux programming tool GCC to compile C code, it will try to complete the compilation at least and make the compiled code easy to debug. easy debugging means that the compiled code has the same execution order as the source code, and the compiled code has not been optimized. there are many options that can be used to tell GCC to generate smaller and faster executable files at the expense of more Compilation Time and easier debugging. the most typical options are-O and-O2.

The-O option tells GCC to optimize the source code. in most cases, these optimizations make program execution faster. -The O2 option tells GCC to generate code as small as possible and as fast as possible. the-O2 option will make compilation faster than-O. however, code execution is usually faster.

In addition to the-O and-O2 optimization options, there are also some low-level options for generating faster code. these options are very special, and it is best to use them only when you fully understand the effects these options will have on the compiled code. for a detailed description of these options, refer to the GCC guide page and type man gcc on the command line. debugging and profiling options
GCC supports several debugging and profiling options. Among these options,-g and-pg options are most commonly used.
The-g option tells GCC to generate debugging information that can be used by the GNU Debugger to debug your program. GCC provides a feature that is not available in many other C compilers. in GCC, you can combine-g with-O (to produce optimization code. this is useful because you can debug your code as close as possible to the final product. when you use these two options at the same time, you must be aware that some of your code has been modified by GCC during optimization. for more information about debugging C Programs, see the next section "Debug C Programs with gdb ".
-The pg option tells GCC to add additional code to your program. During execution, gprof profiling information is generated to show the time consumption of your program. for more information about gprof, see "gprof.


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.